android - SherlockFragmentActivity.onSaveInstanceState how to? -


i working on application has multiple fragments, using viewpageindicator library , sherlocakactionbar library. in 1 of fragment, have button call intent startactivityforresult image camera.. error getting savefragmentbasicstate. have worked in activity , know still dont understand how fragment works , people doing make ways make me more confuse. how should save state??

addmonitoring.java

public class addmonitoring extends sherlockfragmentactivity {       private static final string[] content = new string[] { "info",             "budget", "accessibility", "engagement", "effictiveness",             "additional info","documents","picture","video","finalize" };      private fragmentpageradapter adapter;     private viewpager pager;     public static final string prefs_name = "myprefsfile";     private static final int[] icons = new int[] {             r.drawable.ic_info, /* info */             r.drawable.ic_budget, /* budget */             r.drawable.ic_accessibility, /* accessibility */             r.drawable.ic_engagement, /* engagement */             r.drawable.ic_effectiveness, /* effectiveness */             r.drawable.ic_additionalinfo, /* additional info */             r.drawable.ic_documents, /* documents */             r.drawable.ic_photos, /* pictures */             r.drawable.ic_video, /* video */             r.drawable.ic_addmonitoring_info /* save */     };     string projectid;     progressdialog progressdialog;     dbhelper db;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.addmonitoring);         bundle bundle = getintent().getextras();           adapter = new startermenuadapter(getsupportfragmentmanager());         pager = (viewpager) findviewbyid(r.id.pager);         pager.setadapter(adapter);          tabpageindicator indicator = (tabpageindicator)  findviewbyid(r.id.indicator);         indicator.setviewpager(pager);          pager.setcurrentitem(0);      }      class startermenuadapter extends fragmentpageradapter implements             iconpageradapter {         public startermenuadapter(fragmentmanager fm) {             super(fm);         }          @override         public fragment getitem(int position) {             fragment fragmant = null;             switch (position) {             case 0:                 fragmant = new fragment1_info();                 break;             case 1:                 fragmant = new fragment2_budget();                 break;             case 2:                 fragmant = new fragment3_accessibility();                 break;             case 3:                 fragmant = new fragment4_engagement();                 break;             case 4:                 fragmant = new fragment5_effectiveness();                 break;             case 5:                 fragmant = new fragment6_additionalinfo();                 break;             case 6:                 fragmant = new fragment7_document();                 break;             case 7:                 fragmant = new fragment8_pictures();                 break;             case 8:                 fragmant = new fragment9_video();                 break;             case 9:                 fragmant = new fragment10_save();                 break;              default:                 break;             }             return fragmant;         }          @override         public charsequence getpagetitle(int position) {             return content[position % content.length];         }          @override         public int geticonresid(int index) {             return icons[index];         }          @override         public int getcount() {             return content.length;         }     }     @override     public void onbackpressed() {         super.onbackpressed();      }  } 

fragment8_pictures.java

public class fragment8_pictures extends sherlockfragment implements         onclicklistener {  uri capturedimageuri = null;     imageview image1, image2, image3, image4, image5, image6;     @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {      view view = inflater.inflate(r.layout.addmonitoring8_picture,             container, false);     image1 = (imageview) view.findviewbyid(r.id.mon_image1);     image2 = (imageview) view.findviewbyid(r.id.mon_image2);      image1.setonclicklistener(this);     image2.setonclicklistener(this);      return view;  }  @override public void onsaveinstancestate(bundle outstate) {     // todo auto-generated method stub     super.onsaveinstancestate(outstate); }  @override public void onactivitycreated(bundle savedinstancestate) {     // todo auto-generated method stub     super.onactivitycreated(savedinstancestate); }  @override public void onclick(view v) {      switch (v.getid()) {     case r.id.mon_image1:         calendar cal = calendar.getinstance();         file file = new file(environment.getexternalstoragedirectory(),                 ("devcheck_monitoring" + cal.gettimeinmillis() + ".jpg"));         if (!file.exists()) {             try {                 file.createnewfile();             } catch (ioexception e) {                 e.printstacktrace();             }         } else {             file.delete();             try {                 file.createnewfile();             } catch (ioexception e) {                 e.printstacktrace();             }         }         capturedimageuri = uri.fromfile(file);         intent = new intent(                 android.provider.mediastore.action_image_capture);         i.putextra(mediastore.extra_output, capturedimageuri);         getactivity().startactivityforresult(i, 301);          break;      }  }  public void onactivityresult(int requestcode, int resultcode, intent data) {     if (requestcode == 301) {         // bitmap photo = (bitmap) data.getextras().get("data");         // imageview.setimagebitmap(photo);         try {             bitmap bitmap = mediastore.images.media.getbitmap(getactivity().getapplicationcontext().getcontentresolver(),                     capturedimageuri);             image1.setimagebitmap(bitmap);         } catch (filenotfoundexception e) {             e.printstacktrace();         } catch (ioexception e) {             e.printstacktrace();         }     }     } } 

logcat error

08-20 10:58:57.223: e/androidruntime(6131): fatal exception: main 08-20 10:58:57.223: e/androidruntime(6131): java.lang.nullpointerexception 08-20 10:58:57.223: e/androidruntime(6131):     @ android.support.v4.app.fragmentmanagerimpl.savefragmentbasicstate(fragmentmanager.java:1576) 08-20 10:58:57.223: e/androidruntime(6131):     @ android.support.v4.app.fragmentmanagerimpl.saveallstate(fragmentmanager.java:1617) 08-20 10:58:57.223: e/androidruntime(6131):     @ android.support.v4.app.fragmentactivity.onsaveinstancestate(fragmentactivity.java:481) 08-20 10:58:57.223: e/androidruntime(6131):     @ com.actionbarsherlock.app.sherlockfragmentactivity.onsaveinstancestate(sherlockfragmentactivity.java:127) 08-20 10:58:57.223: e/androidruntime(6131):     @ android.app.activity.performsaveinstancestate(activity.java:1152) 08-20 10:58:57.223: e/androidruntime(6131):     @ android.app.instrumentation.callactivityonsaveinstancestate(instrumentation.java:1216) 08-20 10:58:57.223: e/androidruntime(6131):     @ android.app.activitythread.performstopactivityinner(activitythread.java:3257) 08-20 10:58:57.223: e/androidruntime(6131):     @ android.app.activitythread.handlestopactivity(activitythread.java:3316) 08-20 10:58:57.223: e/androidruntime(6131):     @ android.app.activitythread.access$900(activitythread.java:153) 08-20 10:58:57.223: e/androidruntime(6131):     @ android.app.activitythread$h.handlemessage(activitythread.java:1274) 08-20 10:58:57.223: e/androidruntime(6131):     @ android.os.handler.dispatchmessage(handler.java:99) 08-20 10:58:57.223: e/androidruntime(6131):     @ android.os.looper.loop(looper.java:137) 08-20 10:58:57.223: e/androidruntime(6131):     @ android.app.activitythread.main(activitythread.java:5232) 08-20 10:58:57.223: e/androidruntime(6131):     @ java.lang.reflect.method.invokenative(native method) 08-20 10:58:57.223: e/androidruntime(6131):     @ java.lang.reflect.method.invoke(method.java:511) 08-20 10:58:57.223: e/androidruntime(6131):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:794) 08-20 10:58:57.223: e/androidruntime(6131):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:561) 08-20 10:58:57.223: e/androidruntime(6131):     @ dalvik.system.nativestart.main(native method) 


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -