android webview CustomView onHideCustomView nullpointerexception -
hi i'm making android web view app have error.
how can fix error??
please me.
webview mywebview; private mywebchromeclient mwebchromeclient = null; private view mcustomview; private relativelayout mcontentview; private framelayout mcustomviewcontainer; private webchromeclient.customviewcallback mcustomviewcallback; framelayout.layoutparams layoutparameters = new framelayout.layoutparams(framelayout.layoutparams.match_parent, framelayout.layoutparams.match_parent);
...
private class mywebchromeclient extends webchromeclient { public void onhidecustomview() { if (mcustomview == null) { return; } else { getwindow().setflags(windowmanager.layoutparams.flag_force_not_fullscreen,windowmanager.layoutparams.flag_force_not_fullscreen); // hide custom view. mcustomview.setvisibility(view.gone); // remove custom view container. mcustomviewcontainer.removeview(mcustomview); mcustomview = null; mcustomviewcontainer.setvisibility(view.gone); mcustomviewcallback.oncustomviewhidden(); // show content view. mcontentview.setvisibility(view.visible); super.onhidecustomview(); } } } public boolean onkeydown(int key, keyevent event) { if ((mcustomviewcontainer != null)&&(key == keyevent.keycode_back)) { mwebchromeclient.onhidecustomview(); return true; } else if((key == keyevent.keycode_back)&&mywebview.cangoback()){ mywebview.goback(); return true; } return super.onkeydown(key, event); }
log cat
11-12 19:30:56.175 20071-20085/com.bayabro.bayabro v/mediaplayer﹕ callback application 11-12 19:30:56.175 20071-20085/com.bayabro.bayabro v/mediaplayer﹕ callback 11-12 19:30:56.670 20071-20071/com.bayabro.bayabro d/androidruntime﹕ shutting down vm 11-12 19:30:56.670 20071-20071/com.bayabro.bayabro w/dalvikvm﹕ threadid=1: thread exiting uncaught exception (group=0x416992a0) 11-12 19:30:56.670 20071-20071/com.bayabro.bayabro e/androidruntime﹕ fatal exception: main java.lang.nullpointerexception @ com.bayabro.bayabro.myactivity.onkeydown(myactivity.java:169) @ android.view.keyevent.dispatch(keyevent.java:2705) @ android.app.activity.dispatchkeyevent(activity.java:2431) @ com.android.internal.policy.impl.phonewindow$decorview.dispatchkeyevent(phonewindow.java:2028) @ android.view.viewrootimpl.deliverkeyeventpostime(viewrootimpl.java:3852) @ android.view.viewrootimpl.handleimefinishedevent(viewrootimpl.java:3800) @ android.view.viewrootimpl$viewroothandler.handlemessage(viewrootimpl.java:2935) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:4921) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1038) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:805) @ dalvik.system.nativestart.main(native method) 11-12 19:30:57.175 20071-20086/com.bayabro.bayabro v/mediaplayer﹕ message received msg=3, ext1=63, ext2=0
mywebview
never initialized therefor null @ &&mywebview.cangoback()
.
make sure initialize mywebview
calling mywebview = (webview) findviewbyid(r.id.webview)
to avoid npe:
else if(mywebview != null && key == keyevent.keycode_back && mywebview.cangoback()){ mywebview.goback(); return true; }
Comments
Post a Comment