App Crash with WebView -
please me. want put webview in app. if make new project works fine. when want put in app crash.
included mainactivity / java file / layout file / logcat
mainactivity
import android.app.fragmentmanager; import android.os.bundle; import android.support.design.widget.navigationview; import android.support.v4.view.gravitycompat; import android.support.v4.widget.drawerlayout; import android.support.v7.app.actionbardrawertoggle; import android.support.v7.app.appcompatactivity; import android.support.v7.widget.toolbar; import android.view.menu; import android.view.menuitem; import android.webkit.websettings; import android.webkit.webview; import android.webkit.webviewclient; public class mainactivity extends appcompatactivity implements navigationview.onnavigationitemselectedlistener { private webview mwebview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mwebview = (webview) findviewbyid(r.id.webaanhoudingskaart); websettings websettings = mwebview.getsettings(); websettings.setjavascriptenabled(true); // force links , redirects open in webview instead of in browser mwebview.setwebviewclient(new webviewclient()); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout); actionbardrawertoggle toggle = new actionbardrawertoggle( this, drawer, toolbar, r.string.navigation_drawer_open, r.string.navigation_drawer_close); drawer.setdrawerlistener(toggle); toggle.syncstate(); navigationview navigationview = (navigationview) findviewbyid(r.id.nav_view); navigationview.setnavigationitemselectedlistener(this); } @override public void onbackpressed() { drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout); if (drawer.isdraweropen(gravitycompat.start)) { drawer.closedrawer(gravitycompat.start); } else { super.onbackpressed(); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } @suppresswarnings("statementwithemptybody") @override public boolean onnavigationitemselected(menuitem item) { // handle navigation view item clicks here. int id = item.getitemid(); fragmentmanager fragmentmanager = getfragmentmanager(); if (id == r.id.nav_algemeen_toestand) { fragmentmanager.begintransaction() .replace(r.id.content_frame , new algemeen_toestand()) .commit(); } else if (id == r.id.nav_algemeen_opdracht) { fragmentmanager.begintransaction() .replace(r.id.content_frame , new algemeen_opdracht()) .commit(); } else if (id == r.id.nav_algemeen_uitvoering) { fragmentmanager.begintransaction() .replace(r.id.content_frame , new algemeen_uitvoering()) .commit(); } else if (id == r.id.nav_algemeen_verzoring) { fragmentmanager.begintransaction() .replace(r.id.content_frame , new algemeen_verzorging()) .commit(); } else if (id == r.id.nav_algemeen_tunue) { fragmentmanager.begintransaction() .replace(r.id.content_frame , new algemeen_tunue()) .commit(); } else if (id == r.id.nav_algemeen_bevelvoering) { fragmentmanager.begintransaction() .replace(r.id.content_frame , new algemeen_bevelvoering()) .commit(); } else if (id == r.id.nav_algemeen_scenario) { fragmentmanager.begintransaction() .replace(r.id.content_frame , new algemeen_scenario()) .commit(); } else if (id == r.id.nav_operationeel_wedstrijdinformatie) { fragmentmanager.begintransaction() .replace(r.id.content_frame , new operationeel_wedstrijdinformatie()) .commit(); } else if (id == r.id.nav_operationeel_tijdsschema) { fragmentmanager.begintransaction() .replace(r.id.content_frame , new operationeel_tijdsschema()) .commit(); } else if (id == r.id.nav_operationeel_indeling) { fragmentmanager.begintransaction() .replace(r.id.content_frame , new operationeel_indeling()) .commit(); } else if (id == r.id.nav_operationeel_verbindingsschema) { fragmentmanager.begintransaction() .replace(r.id.content_frame , new operationeel_verbindingsschema()) .commit(); } else if (id == r.id.nav_operationeel_stdaion) { fragmentmanager.begintransaction() .replace(r.id.content_frame , new operationeel_stadion()) .commit(); } else if (id == r.id.nav_operationeel_positie) { fragmentmanager.begintransaction() .replace(r.id.content_frame , new operationeel_positie()) .commit(); } else if (id == r.id.nav_operationeel_aanhoudingskaart) { fragmentmanager.begintransaction() .replace(r.id.content_frame , new operationeel_aanhoudingskaart()) .commit(); } else if (id == r.id.nav_operationeel_stdionverboden) { fragmentmanager.begintransaction() .replace(r.id.content_frame , new operationeel_stadionverboden()) .commit(); } drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout); drawer.closedrawer(gravitycompat.start); return true; }
java
package remco.politiewillemiiapp; import android.app.fragment; import android.os.bundle; import android.support.annotation.nullable; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; /** * created remco on 6-4-2016. */ public class operationeel_aanhoudingskaart extends fragment { view myview; @nullable @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { myview = inflater.inflate(r.layout.operationeel_aanhoudingskaart, container, false); return myview; }
layout
<webview android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/webaanhoudingskaart" /> </relativelayout>
logcat
04-21 21:27:41.151 29717-29717/? e/zygote: v2 04-21 21:27:41.151 29717-29717/? i/libpersona: knox_sdcard checking 10375 04-21 21:27:41.151 29717-29717/? i/libpersona: knox_sdcard not persona 04-21 21:27:41.151 29717-29717/? i/selinux: function: selinux_compare_spd_ram, index[1], spd-policy existed. and_ver=sepf_sm-g920f_5.1.1 ver=38 04-21 21:27:41.151 29717-29717/? w/selinux: function: selinux_compare_spd_ram, index[1], priority [2], priority version ve=sepf_secmobile_6.0.1_0004 04-21 21:27:41.151 29717-29717/? e/zygote: accessinfo : 0 04-21 21:27:41.151 29717-29717/? w/selinux: selinux: seapp_context_lookup: seinfo=default, level=s0:c512,c768, pkgname=remco.politiewillemiiapp 04-21 21:27:41.151 29717-29717/? i/art: late-enabling -xcheck:jni 04-21 21:27:41.181 29717-29717/? d/timakeystoreprovider: timasignature unavailable 04-21 21:27:41.181 29717-29717/? d/activitythread: added timakeystore provider 04-21 21:27:41.221 29717-29717/remco.politiewillemiiapp w/resourcesmanager: gettoplevelresources: /data/app/remco.politiewillemiiapp-2/base.apk / 1.0 running in remco.politiewillemiiapp rsrc of package remco.politiewillemiiapp 04-21 21:27:41.221 29717-29717/remco.politiewillemiiapp i/injectionmanager: inside getclasslibpath + mlibmap{0=, 1=} 04-21 21:27:41.221 29717-29717/remco.politiewillemiiapp d/resourcesmanager: user 0 new overlays fetched null 04-21 21:27:41.241 29717-29717/remco.politiewillemiiapp i/injectionmanager: inside getclasslibpath caller 04-21 21:27:41.241 29717-29717/remco.politiewillemiiapp w/system: classloader referenced unknown path: /data/app/remco.politiewillemiiapp-2/lib/arm64 04-21 21:27:41.241 29717-29717/remco.politiewillemiiapp d/injectionmanager: injectionmanager 04-21 21:27:41.241 29717-29717/remco.politiewillemiiapp d/injectionmanager: fillfeaturestoremap remco.politiewillemiiapp 04-21 21:27:41.241 29717-29717/remco.politiewillemiiapp i/injectionmanager: constructor remco.politiewillemiiapp, feature store :{} 04-21 21:27:41.241 29717-29717/remco.politiewillemiiapp i/injectionmanager: featurestore :{} 04-21 21:27:41.251 29717-29717/remco.politiewillemiiapp w/resourcesmanager: gettoplevelresources: /data/app/remco.politiewillemiiapp-2/base.apk / 1.0 running in remco.politiewillemiiapp rsrc of package remco.politiewillemiiapp 04-21 21:27:41.251 29717-29717/remco.politiewillemiiapp w/resourcesmanager: gettoplevelresources: /data/app/remco.politiewillemiiapp-2/base.apk / 1.0 running in remco.politiewillemiiapp rsrc of package remco.politiewillemiiapp 04-21 21:27:41.321 29717-29717/remco.politiewillemiiapp d/abslistview: motionrecognitionmanager 04-21 21:27:41.321 29717-29717/remco.politiewillemiiapp e/motionrecognitionmanager: mscontextservice = android.hardware.scontext.iscontextservice$stub$proxy@c948c05 04-21 21:27:41.321 29717-29717/remco.politiewillemiiapp e/motionrecognitionmanager: motionservice = com.samsung.android.motion.imotionrecognitionservice$stub$proxy@ec7545a 04-21 21:27:41.321 29717-29717/remco.politiewillemiiapp e/motionrecognitionmanager: motionservice = com.samsung.android.motion.imotionrecognitionservice$stub$proxy@ec7545a 04-21 21:27:41.821 29717-29717/remco.politiewillemiiapp d/skia: ---- fasset->read(2769) returned 0 04-21 21:27:41.831 29717-29717/remco.politiewillemiiapp d/androidruntime: shutting down vm 04-21 21:27:41.831 29717-29717/remco.politiewillemiiapp e/androidruntime: fatal exception: main process: remco.politiewillemiiapp, pid: 29717 java.lang.runtimeexception: unable start activity componentinfo{remco.politiewillemiiapp/remco.politiewillemiiapp.mainactivity}: java.lang.nullpointerexception: attempt invoke virtual method 'android.webkit.websettings android.webkit.webview.getsettings()' on null object reference @ android.app.activitythread.performlaunchactivity(activitythread.java:3253) @ android.app.activitythread.handlelaunchactivity(activitythread.java:3349) @ android.app.activitythread.access$1100(activitythread.java:221) @ android.app.activitythread$h.handlemessage(activitythread.java:1794) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:158) @ android.app.activitythread.main(activitythread.java:7224) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1230) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1120) caused by: java.lang.nullpointerexception: attempt invoke virtual method 'android.webkit.websettings android.webkit.webview.getsettings()' on null object reference @ remco.politiewillemiiapp.mainactivity.oncreate(mainactivity.java:26) @ android.app.activity.performcreate(activity.java:6876) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1135) @ android.app.activitythread.performlaunchactivity(activitythread.java:3206) @ android.app.activitythread.handlelaunchactivity(activitythread.java:3349) @ android.app.activitythread.access$1100(activitythread.java:221) @ android.app.activitythread$h.handlemessage(activitythread.java:1794) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:158) @ android.app.activitythread.main(activitythread.java:7224) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1230) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1120)
you haven't initialized websetting, showing error "null object reference". please initialize , rerun project.
websettings websettings = new websettings();
Comments
Post a Comment