Wednesday, August 4, 2010

[android-developers] Value passed from Javascript to Java through JavaScriptInterface not working

Pl. Hellllppppp,
Why below code is throwing nullPointer exception in last line
(when accessing javaInterface.mValue)
This line through NullPointer, so basically it is not being set. even
though the javascript is correct and has been verified using FireBug
that it returns expected string.


..............................................................................................................

----- There are few lines above this code chunk but it is irrelevant
this problem
-----
------
DemoJavaScriptInterface javaInterface = new
DemoJavaScriptInterface();
storeView.addJavascriptInterface(javaInterface, "demo");
//String jScript4 = "";
solo.sleep(10000);
//storeView.loadUrl("javascript:var
mV=document.getElementById(\"color-link-box-top
\").getElementsByTagName(\"p\")[0].innerHTML;alert(mV);");

solo.sleep(2000);

storeView.loadUrl("javascript:window.demo.Value(document.getElementById(\"color-
link-box-top\").getElementsByTagName(\"p\")[0].innerHTML)");


System.out.println(javaInterface.mValue); //This line
through NullPointer, so basically it is not being set.
//Assert.assert()

}


final class DemoJavaScriptInterface
{

String mValue;
public void Value(String myVal)
{
mValue = myVal;
}
DemoJavaScriptInterface() {
}

}

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate