android - Webview not initializing -
when ever try use web view gives me null pointer exception, code:
import android.app.activity; import android.os.bundle; import android.webkit.webchromeclient; import android.webkit.webview; public class main extends activity { webview webview; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); webview = (webview)findviewbyid(r.id.webview); webview.getsettings().setjavascriptenabled(true); webview.setwebchromeclient(new webchromeclient()); webview.loadurl("file:///android_asset/www/index.html"); } }
the logs are:
02-18 22:08:06.224: error/androidruntime(355): java.lang.runtimeexception: unable start activity componentinfo{com.test.web/com.test.web.main}: java.lang.nullpointerexception 02-18 22:08:06.224: error/androidruntime(355): caused by: java.lang.nullpointerexception 02-18 22:08:06.224: error/androidruntime(355): @ com.test.web.main.oncreate(main.java:17)
(there more logs none of them pertained problem)
on semi- related note how make code code on stackexchange?
so i'm guessing webview isn't initializing correctly?
you're getting nullpointerexception because in main.xml file have defined textview not webview.
just change textview webview
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="schemas.android.com/apk/res/android"; android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <webview android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/webview" /> </linearlayout>
Comments
Post a Comment