I have included HTML page inside codename one application, I need to modify the content (I am trying to modify the html page using JavascriptContext
) and when I try to do that, it always gives me null pointer on the object. I doubled checked the id for the component that I am trying to modify.
So can you provide any code snippet or example on the correct way to modify the html page from inside the code?
WebBrowser b = new WebBrowser() {
@Override
public void onLoad(String url) {
// TODO Auto-generated method stub super.onLoad(url);
jsObject = (JSObject)ctx.get("testing");
System.out.println(jsObject.get(0));
}
};
browser = (BrowserComponent)b.getInternal();
ctx = new JavascriptContext(browser);
url="jar:///"+formName+".html";
b.setURL(url);
The html body has
<p id = "testing" >hello there what's up</p>
as per Shai request adding the stack trace :
document.getElementById('testing').innerHTML = 'set from eclipse';
Exception in thread "JavaFX Application Thread" netscape.javascript.JSException: TypeError: null is not an object (evaluating 'document.getElementById('testing').innerHTML = 'set from eclipse'')
at com.sun.webkit.dom.JSObject.fwkMakeException(Unknown Source)
at com.sun.webkit.WebPage.twkExecuteScript(Native Method)
at com.sun.webkit.WebPage.executeScript(Unknown Source)
at javafx.scene.web.WebEngine.executeScript(Unknown Source)
at com.codename1.impl.javase.SEBrowserComponent$9.run(SEBrowserComponent.java:215)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$149(Unknown Source)
at java.lang.Thread.run(Unknown Source)
null
hello there what's up
` in the body – AhMaD AbUIeSa Dec 14 '16 at 08:42