android - Error getting while loading new html file when clicked on the actiobar actionirem(sherlock) -


i have application whihc using sherlock actionbar , ahve splited actionbar. trying load next html file when clicked on next item in actionbar. shows me error. here code.

activity.java :

public class tutorialviewactivity extends sherlockactivity {      // tutorial no     int tutorialno;      // progress dialog     progressdialog mprogress;      // share string     string copy;      // string url     string url;      // settings values - completed     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          // check settings         settings();         // check full screen         if (fullscreen_sett == true) {             // hide statusbar of android             getwindow().setflags(windowmanager.layoutparams.flag_fullscreen,                     windowmanager.layoutparams.flag_fullscreen);          }          // orientation settings         if (orientation_sett.equals("portrait")) {             setrequestedorientation(activityinfo.screen_orientation_portrait);         } else if (orientation_sett.equals("landscape")) {             setrequestedorientation(activityinfo.screen_orientation_landscape);          } else {             setrequestedorientation(activityinfo.screen_orientation_sensor);         }          // showing layout         setcontentview(r.layout.tutorialview_layout);          // backlight on/off         if (backlight_sett == true) {             getwindow()                     .addflags(windowmanager.layoutparams.flag_keep_screen_on);         }          // getting strings(level) main activity         bundle extras = getintent().getextras();         string tutorialname = extras.getstring("tutorialname");         tutorialno = extras.getint("tutorialno");         tutorialno++;          // loading file html link         url = "file:///android_asset/tutorials/" + tutorialno                 + "/androidtutorial.html";          string copy_share = "tutorials" + tutorialno + "/copyshare.txt";         // getting text copy share         try {             copy = readtxt(copy_share);         } catch (ioexception e) {             // todo auto-generated catch block             e.printstacktrace();         }         // actionbar         actionbar actionbar = getsupportactionbar();         actionbar.settitle("chapter " + " : " + tutorialno);         actionbar.setsubtitle(tutorialname);         actionbar.setdisplayhomeasupenabled(true);         actionbar.sethomebuttonenabled(true);          // method called tutorialview         tutorialview();      }      /************************************ settings ******************/     public void settings() {         // settings         sharedpreferences sp = preferencemanager                 .getdefaultsharedpreferences(this);         zoom_sett = sp.getboolean("zoomcontrols_settings", true);         fitscreen_settings = sp.getboolean("fitscreen_settings", false);         animation_sett = sp.getboolean("animations_settings", true);         fullscreen_sett = sp.getboolean("fullscreen_settings", false);         backlight_sett = sp.getboolean("backlight_settings", false);         orientation_sett = sp.getstring("orientation_settings", "sensor");      }      // method tutorial view     public void tutorialview() {         // webview         webview wv = (webview) findviewbyid(r.id.tutorialwebview);          // webview settings         websettings websettings = wv.getsettings();          // if (orientation_sett.equals("portrait")) {         // new webview         wv = new webview(this);         // contentview of webview progressdialog         setcontentview(wv);          // state of progress dialog         mprogress = progressdialog.show(this, "loading",                 "please wait moment...");          // add webviewclient webview, handles loading         // data         // web         wv.setwebviewclient(new webviewclient() {             // load url             public boolean shouldoverrideurlloading(webview view, string url) {                 // setrequestedorientation(activityinfo.screen_orientation_sensor);                 view.loadurl(url);                 return true;             }              // when finish loading page             public void onpagefinished(webview view, string url) {                 if (mprogress.isshowing()) {                     mprogress.dismiss();                 }              }          });         // }         // webview controls         if (zoom_sett == true) {             websettings.setbuiltinzoomcontrols(true);             wv.loadurl(url);         } else if (fitscreen_settings == true) {             websettings.setbuiltinzoomcontrols(true);             websettings.setloadwithoverviewmode(true);             websettings.setusewideviewport(true);             wv.loadurl(url);         } else {              wv.loadurl(url);         }     }      /****************************************************************************/      // dropdown menu      @override     public boolean oncreateoptionsmenu(com.actionbarsherlock.view.menu menu) {         getsupportmenuinflater().inflate(r.menu.tutorialview, menu);         return super.oncreateoptionsmenu(menu);     }      /****************************************************************************/      @targetapi(build.version_codes.honeycomb)     @suppresslint("newapi")     @suppresswarnings("deprecation")     public boolean onmenuitemselected(int featureid, menuitem item) {          int itemid = item.getitemid();         switch (itemid) {         // home actionbar         case android.r.id.home:              onbackpressed();              break;          case r.id.copy:             int sdk = android.os.build.version.sdk_int;             if (sdk < android.os.build.version_codes.honeycomb) {                 android.text.clipboardmanager clipboard = (android.text.clipboardmanager) getsystemservice(context.clipboard_service);                 clipboard.settext(copy);                 toast.maketext(getapplicationcontext(), "coped clipboard",                         toast.length_short).show();             } else {                 android.content.clipboardmanager clipboard = (android.content.clipboardmanager) getsystemservice(context.clipboard_service);                 android.content.clipdata clip = android.content.clipdata                         .newplaintext("", copy);                 clipboard.setprimaryclip(clip);                 toast.maketext(getapplicationcontext(), "coped clipboard",                         toast.length_short).show();             }             break;          case r.id.next:              tutorialno++;             // loading file html link             url = "file:///android_asset/tutorials/" + tutorialno                     + "/androidtutorial.html";             // method called tutorialview             //tutorialview();              webview wv = (webview) findviewbyid(r.id.tutorialwebview);             wv.loadurl(url);             toast.maketext(getapplicationcontext(), "next", toast.length_short).show();         }          return true;     }// home actionbar end      // reading textfiles     public string readtxt(string copy_share) throws ioexception {          inputstream inputstream = getassets().open(copy_share);         // system.out.println(inputstream);         bytearrayoutputstream bytearrayoutputstream = new bytearrayoutputstream();          int i;         try {             = inputstream.read();             while (i != -1) {                 bytearrayoutputstream.write(i);                 = inputstream.read();             }             inputstream.close();         } catch (ioexception e) {             // todo auto-generated catch block             e.printstacktrace();         }          return bytearrayoutputstream.tostring();     }      // go     @override     public void onbackpressed() {          super.finish();         if (animation_sett == true) {             // fading transition effect             tutorialviewactivity.this.overridependingtransition(                     android.r.anim.fade_in, android.r.anim.fade_out);         }      }// end go  } 

logcat error:

08-08 12:53:18.986: e/androidruntime(4312): fatal exception: main 08-08 12:53:18.986: e/androidruntime(4312): java.lang.nullpointerexception 08-08 12:53:18.986: e/androidruntime(4312):     @ com.danaraddi.androidtutorial.tutorialviewactivity.onmenuitemselected(tutorialviewactivity.java:233) 08-08 12:53:18.986: e/androidruntime(4312):     @ com.actionbarsherlock.actionbarsherlock.callbackoptionsitemselected(actionbarsherlock.java:604) 08-08 12:53:18.986: e/androidruntime(4312):     @ com.actionbarsherlock.internal.actionbarsherlocknative.dispatchoptionsitemselected(actionbarsherlocknative.java:92) 08-08 12:53:18.986: e/androidruntime(4312):     @ com.actionbarsherlock.app.sherlockactivity.onoptionsitemselected(sherlockactivity.java:159) 08-08 12:53:18.986: e/androidruntime(4312):     @ android.app.activity.onmenuitemselected(activity.java:2548) 08-08 12:53:18.986: e/androidruntime(4312):     @ com.android.internal.policy.impl.phonewindow.onmenuitemselected(phonewindow.java:980) 08-08 12:53:18.986: e/androidruntime(4312):     @ com.android.internal.view.menu.menubuilder.dispatchmenuitemselected(menubuilder.java:735) 08-08 12:53:18.986: e/androidruntime(4312):     @ com.android.internal.view.menu.menuitemimpl.invoke(menuitemimpl.java:149) 08-08 12:53:18.986: e/androidruntime(4312):     @ com.android.internal.view.menu.menubuilder.performitemaction(menubuilder.java:874) 08-08 12:53:18.986: e/androidruntime(4312):     @ com.android.internal.view.menu.actionmenuview.invokeitem(actionmenuview.java:547) 08-08 12:53:18.986: e/androidruntime(4312):     @ com.android.internal.view.menu.actionmenuitemview.onclick(actionmenuitemview.java:115) 08-08 12:53:18.986: e/androidruntime(4312):     @ android.view.view.performclick(view.java:4202) 08-08 12:53:18.986: e/androidruntime(4312):     @ android.view.view$performclick.run(view.java:17340) 08-08 12:53:18.986: e/androidruntime(4312):     @ android.os.handler.handlecallback(handler.java:725) 08-08 12:53:18.986: e/androidruntime(4312):     @ android.os.handler.dispatchmessage(handler.java:92) 08-08 12:53:18.986: e/androidruntime(4312):     @ android.os.looper.loop(looper.java:137) 08-08 12:53:18.986: e/androidruntime(4312):     @ android.app.activitythread.main(activitythread.java:5039) 08-08 12:53:18.986: e/androidruntime(4312):     @ java.lang.reflect.method.invokenative(native method) 08-08 12:53:18.986: e/androidruntime(4312):     @ java.lang.reflect.method.invoke(method.java:511) 08-08 12:53:18.986: e/androidruntime(4312):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 08-08 12:53:18.986: e/androidruntime(4312):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 08-08 12:53:18.986: e/androidruntime(4312):     @ dalvik.system.nativestart.main(native method) 

tutorialview layout :

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/linearlayout01"     android:layout_width="fill_parent"     android:layout_height="fill_parent"    >      <webview         android:id="@+id/tutorialwebview"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:paddingleft="10dp" /> </linearlayout> 

ok,

in tutorialview() locating xml tag webview android:id="@+id/tutorialwebview" wv, overwriting , creating new one. , setting screen that.

then when try locate again, comes null beacuse new webview has no id.

in tutorialview(), comment out new webview creation.

 // webview     webview wv = (webview) findviewbyid(r.id.tutorialwebview);      // webview settings     websettings websettings = wv.getsettings();      // if (orientation_sett.equals("portrait")) {     // new webview          //   wv = new webview(this);   *<---comment line out (has no id set either)*    // contentview of webview progressdialog     setcontentview(wv); 

or

change case switch block , rid of findviewbyid line follows

case r.id.next:

        tutorialno++;         // loading file html link         url = "file:///android_asset/tutorials/" + tutorialno                 + "/androidtutorial.html";         // method called tutorialview         //tutorialview();        // *delete line*            webview wv = (webview) findviewbyid(r.id.tutorialwebview);          wv.loadurl(url);         // dont use   getapplicationcontext() toasts,  use activity (this)         toast.maketext(this, "next", toast.length_short).show();     } 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -