i have a problem in loading url in my webview. i put my code in onCreate so that when this activity called it would directly load the url in webview widget. I use this code.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loadurl);
webView_url = (WebView)findViewById(R.id.imageView1);
webView_url.getSettings().setJavaScriptEnabled(true);
webView_url.loadUrl("http://www.google.com");
}
Everytime i put this code in my activity it always force close and my logcat error is
08-02 08:37:04.780: E/AndroidRuntime(10321): FATAL EXCEPTION: main
08-02 08:37:04.780: E/AndroidRuntime(10321): java.lang.RuntimeException: Unable to
start activity
ComponentInfo{com.example.qrreader/com.example.qrreader.LoadurlActivity}:
java.lang.NullPointerException
08-02 08:37:04.780: E/AndroidRuntime(10321): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-02 08:37:04.780: E/AndroidRuntime(10321): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-02 08:37:04.780: E/AndroidRuntime(10321): at
android.app.ActivityThread.access$600(ActivityThread.java:123)
08-02 08:37:04.780: E/AndroidRuntime(10321): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-02 08:37:04.780: E/AndroidRuntime(10321): at
android.os.Handler.dispatchMessage(Handler.java:99)
08-02 08:37:04.780: E/AndroidRuntime(10321): at
android.os.Looper.loop(Looper.java:137)
08-02 08:37:04.780: E/AndroidRuntime(10321): at
android.app.ActivityThread.main(ActivityThread.java:4424)
08-02 08:37:04.780: E/AndroidRuntime(10321): at
java.lang.reflect.Method.invokeNative(Native Method)
08-02 08:37:04.780: E/AndroidRuntime(10321): at
java.lang.reflect.Method.invoke(Method.java:511)
08-02 08:37:04.780: E/AndroidRuntime(10321): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-02 08:37:04.780: E/AndroidRuntime(10321): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-02 08:37:04.780: E/AndroidRuntime(10321): at
dalvik.system.NativeStart.main(Native Method)
08-02 08:37:04.780: E/AndroidRuntime(10321): Caused by: java.lang.NullPointerException
08-02 08:37:04.780: E/AndroidRuntime(10321): at
com.example.qrreader.LoadurlActivity.onCreate(LoadurlActivity.java:36)
08-02 08:37:04.780: E/AndroidRuntime(10321): at
android.app.Activity.performCreate(Activity.java:4465)
08-02 08:37:04.780: E/AndroidRuntime(10321): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-02 08:37:04.780: E/AndroidRuntime(10321): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-02 08:37:04.780: E/AndroidRuntime(10321): ... 11 more
Please anyone help me.
<uses-permission android:name="android.permission.INTERNET" />
? Also isWebView webView_url;
declared outsideonCreate()
?LoadurlActivity.java:36
?imageView1
in your layout inactivity_loadurl
? Looks a bit weird that aWebView
has an id that is more appropriate for anImageView
.findViewById
returns null if there is no view with such id.LoadUrlActivity
? Also please post your XML file.