I have an app that has a bunch of links and when a user clicks a link, it opens the browser and display the link. With Android, the user can hit the back button and get back to the app. On the blackberry, this is supposedly not possible.
What im trying to do is have half the screen a list view and the other half a WebView and display information like that. Problem arrises when using a WebView itself, for some reason its not working. I have the webview created in XML and call in code by that.
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("Http://www.google.com");
mWebView.setWebViewClient(new HelloWebViewClient());
and i get this error.
02-16 21:56:23.081: E/AndroidRuntime(25833564): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testing/com.testing.Testing}: java.lang.NullPointerException
02-16 21:56:23.081: E/AndroidRuntime(25833564): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
02-16 21:56:23.081: E/AndroidRuntime(25833564): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
02-16 21:56:23.081: E/AndroidRuntime(25833564): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-16 21:56:23.081: E/AndroidRuntime(25833564): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-16 21:56:23.081: E/AndroidRuntime(25833564): at android.os.Handler.dispatchMessage(Handler.java:99)
02-16 21:56:23.081: E/AndroidRuntime(25833564): at android.os.Looper.loop(Looper.java:123)
02-16 21:56:23.081: E/AndroidRuntime(25833564): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-16 21:56:23.081: E/AndroidRuntime(25833564): at java.lang.reflect.Method.invokeNative(Native Method)
02-16 21:56:23.081: E/AndroidRuntime(25833564): at java.lang.reflect.Method.invoke(Method.java:507)
02-16 21:56:23.081: E/AndroidRuntime(25833564): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
02-16 21:56:23.081: E/AndroidRuntime(25833564): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
02-16 21:56:23.081: E/AndroidRuntime(25833564): at dalvik.system.NativeStart.main(Native Method)
02-16 21:56:23.081: E/AndroidRuntime(25833564): Caused by: java.lang.NullPointerException
02-16 21:56:23.081: E/AndroidRuntime(25833564): at com.testing.Testing.onCreate(Testing.java:62)
02-16 21:56:23.081: E/AndroidRuntime(25833564): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
02-16 21:56:23.081: E/AndroidRuntime(25833564): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
02-16 21:56:23.081: E/AndroidRuntime(25833564): ... 11 more
The caused by (line 62) points to the javaScriptEnabled line. If i comment out that line then it points to the loadUrl line. mWebView is a public static variable. Has anyone experienced this problem and knows of a fix?
I figured it out, i placed the code before i set the content of the activity. It worked flawlessly once set the content first.