eclipse - Android Converting Object to String Array -


to set scene: have fragment executes asynctask. here fragment.

package com.ib.ecko;  import android.os.bundle; import android.annotation.suppresslint; import android.app.fragment; import android.graphics.bitmap; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.imagebutton; import android.widget.textview;  @suppresslint("newapi") public class profilefragment extends fragment {  public object objarr[] = new object[3]; bitmap profileimages[]; string userinfo[] = new string[6]; string userinfo2[]; string summary; private imagebutton profileimagebutton; private textview usernametextview; private textview agetextview; private textview personalitytextview; private textview summarytextview;  public view oncreateview(layoutinflater inflater, viewgroup container,         bundle savedinstancestate) {     view v = inflater.inflate(r.layout.activity_profile_fragment, container, false);      profileimagebutton = (imagebutton) v.findviewbyid(r.id.profileimagebutton);     usernametextview = (textview)  v.findviewbyid(r.id.profileviewusernametextview);     agetextview = (textview) v.findviewbyid(r.id.profileviewagetextview);     personalitytextview = (textview) v.findviewbyid(r.id.profileviewpersonalitytextview);     summarytextview = (textview) v.findviewbyid(r.id.profileviewsummarytextview);      //download profile     networkasyncdownload task = new networkasyncdownload(objarr);     task.execute();     // inflate layout fragment     return v; } public void setviews(){     userinfo = (string[]) objarr[0];     profileimages = (bitmap[]) objarr[1];     summary = (string) objarr[2];     userinfo2 = (string[]) objarr[3];     profileimagebutton.setimagebitmap(profileimages[0]);     usernametextview.settext(userinfo[0]);     personalitytextview.settext(userinfo2[4]);     agetextview.settext(userinfo[3]);     summarytextview.settext(summary); }  } 

here asynctask.

package com.ib.ecko;  import java.io.file; import java.io.fileinputstream; import java.io.filenotfoundexception; import java.io.fileoutputstream; import java.io.ioexception; import java.io.objectinputstream; import java.io.objectoutputstream; import java.lang.ref.weakreference; import java.net.socketexception;  import org.apache.commons.net.ftp.ftp; import org.apache.commons.net.ftp.ftpclient; import org.apache.commons.net.ftp.ftpreply;  import android.content.context;  import android.graphics.bitmap; import android.os.asynctask; import android.os.environment; import android.widget.imagebutton; import android.widget.textview;  public class networkasyncdownload extends asynctask<void, void, object[]> {    fileoutputstream desfilestream; fileinputstream fileinputstream; objectinputstream objectinputstream; object input1; object input2; object input3; object input4; object objarr[]; bitmap profileimages[]; string userinfo[]; string userinfo2[]; string summary;  private final weakreference<object[]> objarrref;  public networkasyncdownload(object obj[]){      objarrref = new weakreference<object[]>(obj);  }  @override protected object[] doinbackground(void... params) {          desfilestream = new fileoutputstream(path + "juifromserver");         mftpclient.retrievefile("jui", desfilestream);         fileinputstream = new fileinputstream(path + "juifromserver");         objectinputstream = new objectinputstream(fileinputstream);         input1 = objectinputstream.readobject();         mftpclient.retrievefile("profilepictures", desfilestream);         input2 = objectinputstream.readobject();         mftpclient.retrievefile("summary", desfilestream);         input3 = objectinputstream.readobject();         mftpclient.retrievefile("jui2", desfilestream);         input4 = objectinputstream.readobject();         objarr = new object[] {input1, input2, input3, input4};      } catch (socketexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     } catch (classnotfoundexception e) {         e.printstacktrace();     }     return objarr; }  protected void onpostexecute(object object[]) {      objarr = objarrref.get();      objarr = object;      profilefragment setviews = new profilefragment();      setviews.objarr = object;      setviews.setviews();  }  } 

when load fragment, here error log gives me.

10-07 03:28:21.358: e/androidruntime(7759): fatal exception: main 10-07 03:28:21.358: e/androidruntime(7759): java.lang.nullpointerexception 10-07 03:28:21.358: e/androidruntime(7759):     @ com.ib.ecko.profilefragment.setviews(profilefragment.java:44) 10-07 03:28:21.358: e/androidruntime(7759):     @ com.ib.ecko.networkasyncdownload.onpostexecute(networkasyncdownload.java:85) 10-07 03:28:21.358: e/androidruntime(7759):     @ com.ib.ecko.networkasyncdownload.onpostexecute(networkasyncdownload.java:1) 10-07 03:28:21.358: e/androidruntime(7759):     @ android.os.asynctask.finish(asynctask.java:631) 10-07 03:28:21.358: e/androidruntime(7759):     @ android.os.asynctask.access$600(asynctask.java:177) 10-07 03:28:21.358: e/androidruntime(7759):     @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:644) 10-07 03:28:21.358: e/androidruntime(7759):     @ android.os.handler.dispatchmessage(handler.java:99) 10-07 03:28:21.358: e/androidruntime(7759):     @ android.os.looper.loop(looper.java:137) 10-07 03:28:21.358: e/androidruntime(7759):     @ android.app.activitythread.main(activitythread.java:5227) 10-07 03:28:21.358: e/androidruntime(7759):     @ java.lang.reflect.method.invokenative(native method) 10-07 03:28:21.358: e/androidruntime(7759):     @ java.lang.reflect.method.invoke(method.java:511) 10-07 03:28:21.358: e/androidruntime(7759):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:795) 10-07 03:28:21.358: e/androidruntime(7759):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:562) 10-07 03:28:21.358: e/androidruntime(7759):     @ de.robv.android.xposed.xposedbridge.main(xposedbridge.java:110) 10-07 03:28:21.358: e/androidruntime(7759):     @ dalvik.system.nativestart.main(native method) 

the error seems caused :

java.lang.nullpointerexception 10-07 03:28:21.358:e/androidruntime(7759): @ com.ib.ecko.profilefragment.setviews(profilefragment.java:44) 

which line right here: userinfo = (string[]) objarr[0];

sorry naming, wasn't intention code reader friendly. objarr array of objects had saved. objarr[0] string array. have done before in different activity not quite complicated whole fragment , asynctask stuff going on, within activity. i'm not sure what's causing error. you'll see redundant code result of me trying random things make work , see caused it. also, deleted network code stuff. let me know if should tidy post it's easier read.

seems have profilefragment.objarr = new object[3], each of objects null.

when initialices array (new object[]) reserve space contains objects, each object null until instance its. example, this:

profilefragment.objarr[0] = new string[6]; 

then, can do:

userinfo = (string[]) objarr[0]; userinfo[0] = "name"; userinfo[1] = "surname"; .... 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -