java - unfortunately app has stopped in android emulator after adding webview -
i trying build android application takes input[array values] java , passing java script , html file. have created web view concept. when execute app not working. here code. html file take array values , plot graph
package com.example.helloworld; import android.os.bundle; import android.webkit.javascriptinterface; import android.webkit.webview; import org.apache.cordova.*; public class mainactivity extends droidgap { webview webview; final class chartdataloader{ @javascriptinterface public double[][] getdata(){ double[][] data = { {10,10}, {20, 10} }; return data; } } public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); //setcontentview(r.layout.activity_main); webview.addjavascriptinterface(new chartdataloader(), "dataloader"); webview.loadurl("file:///android_asset/www/index.html"); } } html file
<html> <head> <script type="text/javascript" src="jscharts.js"></script> </head> <body> <div id="chartcontainer">you should see chart here.</div> <script type="text/javascript"> mydata = dataloader.getdata(); alert("datareceived: " + mydata.length); alert("element 0 : " + mydata[0]); var mychart = new jschart('chartcontainer', 'line'); mychart.setdataarray(mydata); mychart.draw(); </script> </body> </html>
from comments droidgap emulator name.
so change to
public class mainactivity extends activity { this
//setcontentview(r.layout.activity_main); // uncomment is commented
and webview not initialized.
example:
webview webview; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); webview = (webview) findviewbyid(r.id.webview1); // missing
Comments
Post a Comment