I'm getting a NullPointerException
on the following call in Android 2.3.4:
java.lang.NullPointerException
at android.webkit.WebView.addPackageNames(WebView.java:4063)
at com.my.company.MyClass$MyInnerClass.myMethod(MyClass.java:283)
at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
at android.webkit.BrowserFrame.loadUrl(BrowserFrame.java:246)
at android.webkit.WebViewCore.loadUrl(WebViewCore.java:1981)
at android.webkit.WebViewCore.access$1400(WebViewCore.java:53)
at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1122)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:674)
at java.lang.Thread.run(Thread.java:1019)
MyClass$MyInnerClass is added to the JavaScript interface as
class MyClass {
// ...
myWebView.addJavascriptInterface(new MyInnerClass(), "MyInnerClass");
// ...
public void myOuterMethod(int param1, int param2) {
// Notify a listener that myOuterMethod was called
}
private class MyInnerClass {
public void myMethod(int param1, int param2) {
myOuterMethod(param1, param2);
}
}
}
So, the JavaScript call MyInnerClass.myMethod(-1, -1)
seems to come over the Java-JavaScript bridge fine, but fails in the addPackageNames
call, which isn't my code.
I've looked at the android.webkit.WebView
class in GrepCode, but I can't figure out how I could have caused this. The only line in addPackageNames
is
public void addPackageNames(Set<String> packageNames) {
mWebViewCore.sendMessage(EventHub.ADD_PACKAGE_NAMES, packageNames);
}
So, I've come to the conclusion that either mWebViewCore
or EventHub
is null
.
Can any Android experts shed some light on this? Is this a known bug? Did I cause this? If so, how? If not, how might I prevent this?