修改本地html页面代号一个?

时间:2016-12-14 07:04:44

标签: java cross-platform codenameone

我在一个应用程序中包含HTML页面,我需要修改内容(我试图使用JavascriptContext修改html页面)当我尝试这样做时,它总是给我空指针物体。我加倍检查了我试图修改的组件的id。

那么你能否以正确的方式提供任何代码片段或示例来修改代码中的html页面?

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);

html正文

<p id = "testing" >hello there what's up</p> 

根据Shai请求添加堆栈跟踪:

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

0 个答案:

没有答案