i'm trying application written in javafx ported across android , part have been successful in attempts. in application run on android after packaging apk file using netbeans ide , gradle.
but problem have application crash when trying access google map through javafx webview component. using following in javafx:
googlemapengine.load(getclass().getresource("/googlelondonmap.html").toexternalform());
and html file located under resources folder in gradle root folder.
when test application in netbeans right clicking on gradle root node , selecting tasks --> run --> run. application runs perfectly, including accessing google map using html file , javafx webview.
the creation of apk file successful in using tasks --> android --> android. once install apk file on android device , access google map portion of application throws me out of application saying "unfortunately has stopped". clues on how fix this?
looking @ log file created using adb command saw following output:
e/androidruntime( 6038): fatal exception: javafx application thread e/androidruntime( 6038): process: com.sundaethepugapp, pid: 6038 e/androidruntime( 6038): java.lang.runtimeexception: java.lang.reflect.invocationtargetexception e/androidruntime( 6038): @ javafx.fxml.fxmlloader$methodhandler.invoke(fxmlloader.java:1774) e/androidruntime( 6038): @ javafx.fxml.fxmlloader$controllermethodeventhandler.handle(fxmlloader.java:1657) e/androidruntime( 6038): @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(compositeeventhandler.java:86) e/androidruntime( 6038): @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:238) e/androidruntime( 6038): @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:191) e/androidruntime( 6038): @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent(compositeeventdispatcher.java:59) e/androidruntime( 6038): @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:58) e/androidruntime( 6038): @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) e/androidruntime( 6038): @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) e/androidruntime( 6038): @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) e/androidruntime( 6038): @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) e/androidruntime( 6038): @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) e/androidruntime( 6038): @ com.sun.javafx.event.eventutil.fireeventimpl(eventutil.java:74) e/androidruntime( 6038): @ com.sun.javafx.event.eventutil.fireevent(eventutil.java:49) e/androidruntime( 6038): @ javafx.event.event.fireevent(event.java:198) e/androidruntime( 6038): @ javafx.scene.node.fireevent(node.java:8411) e/androidruntime( 6038): @ javafx.scene.control.button.fire(button.java:185) e/androidruntime( 6038): @ com.sun.javafx.scene.control.behavior.buttonbehavior.mousereleased(buttonbehavior.java:182) e/androidruntime( 6038): @ com.sun.javafx.scene.control.skin.behaviorskinbase$1.handle(behaviorskinbase.java:96) e/androidruntime( 6038): @ com.sun.javafx.scene.control.skin.behaviorskinbase$1.handle(behaviorskinbase.java:89) e/androidruntime( 6038): @ com.sun.javafx.event.compositeeventhandler$normaleventhandlerrecord.handlebubblingevent(compositeeventhandler.java:218) e/androidruntime( 6038): @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(compositeeventhandler.java:80) e/androidruntime( 6038): @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:238) e/androidruntime( 6038): @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:191) e/androidruntime( 6038): @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent(compositeeventdispatcher.java:59) e/androidruntime( 6038): @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:58) e/androidruntime( 6038): @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) e/androidruntime( 6038): @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) e/androidruntime( 6038): @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) e/androidruntime( 6038): @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) e/androidruntime( 6038): @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) e/androidruntime( 6038): @ com.sun.javafx.event.eventutil.fireeventimpl(eventutil.java:74) e/androidruntime( 6038): @ com.sun.javafx.event.eventutil.fireevent(eventutil.java:54) e/androidruntime( 6038): @ javafx.event.event.fireevent(event.java:198) e/androidruntime( 6038): @ javafx.scene.scene$mousehandler.process(scene.java:3757) e/androidruntime( 6038): @ javafx.scene.scene$mousehandler.access$1500(scene.java:3485) e/androidruntime( 6038): @ javafx.scene.scene.impl_processmouseevent(scene.java:1762) e/androidruntime( 6038): @ javafx.scene.scene$scenepeerlistener.mouseevent(scene.java:2494) e/androidruntime( 6038): @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(glassvieweventhandler.java:352) e/androidruntime( 6038): @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(glassvieweventhandler.java:275) e/androidruntime( 6038): @ java.security.accesscontroller.doprivileged(accesscontroller.java:52) e/androidruntime( 6038): @ com.sun.javafx.tk.quantum.glassvieweventhandler.lambda$handlemouseevent$336(glassvieweventhandler.java:388) e/androidruntime( 6038): @ com.sun.javafx.tk.quantum.glassvieweventhandler.access$lambda$1(glassvieweventhandler.java) e/androidruntime( 6038): @ com.sun.javafx.tk.quantum.glassvieweventhandler$$lambda$4.get(unknown source) e/androidruntime( 6038): @ com.sun.javafx.tk.quantum.quantumtoolkit.runwithoutrenderlock(quantumtoolkit.java:389) e/androidruntime( 6038): @ com.sun.javafx.tk.quantum.glassviewe
here build.gradle file , yes using verdana font. font coming through ok can see on android device.
buildscript { repositories { jcenter() } dependencies { classpath 'org.javafxports:jfxmobile-plugin:1.0.7' } } apply plugin: 'org.javafxports.jfxmobile' repositories { jcenter() maven { url 'http://nexus.gluonhq.com/nexus/content/repositories/releases' } } mainclassname = 'com.sundaethepugapp.sundaethepugfx' dependencies { compile 'com.gluonhq:charm:2.1.0' androidruntime 'com.gluonhq:charm-android:2.1.0' iosruntime 'com.gluonhq:charm-ios:2.1.0' desktopruntime 'com.gluonhq:charm-desktop:2.1.0' } jfxmobile { android { manifest = 'src/android/androidmanifest.xml' androidsdk = 'c:/users/zermatt/appdata/local/android/android-sdk/' } }
edit
found cause fatal exception. appears android not following block of code:
url resource= getclass().getclassloader().getresource("music/thememusic.mp3"); themesong = new mediaplayer(new media(resource.tostring())); themesong.setonendofmedia(new runnable() { public void run() { themesong.seek(duration.zero); } }); themesong.play();
and block of code comes error message in android:
googlemapengine.load(getclass().getresource("/googlelondonmap.html").toexternalform());
webpage not available: webpage @ jar:file:/data/app/com.sundaethepugapp - 1/base .apk!/googlelondonmap.html not loaded because:
net::err_unknown_url_scheme
so can rectify this?
edit again
experimenting jose solution , building upon it, found way javascript in html working although ain't pretty. code supplied put method (called createandroidurlscheme) , returned string. here code , yes works fine in javafx, not in androids webview again:
string url = createandroidurlscheme("/googletestmap.html"); //system.out.println(url); googlemapengine.loadcontent(url, "text/html"); googlemapengine.setjavascriptenabled(true); googlemapengine.getloadworker().stateproperty().addlistener(new changelistener<worker.state>() { public void changed(final observablevalue<? extends worker.state> observablevalue, final state oldstate, final state newstate) { if (newstate == state.succeeded) { googlemapengine.executescript( "var latlng = new google.maps.latlng(59.438722, 24.745278);" + "var myoptions = {" + "zoom: 15," + "center: latlng," + "maptypeid: google.maps.maptypeid.roadmap," + "maptypecontrol: false," + "navigationcontrol: false," + "streetviewcontrol: false," + "backgroundcolor: '#666970'," + "disabledefaultui: true" + "};" + "" + "var map = new google.maps.map(document.getelementbyid('map_canvas'), myoptions);"); } } });
now through logcat new android fatal exception:
i/system.out( 809): [jvdbg] error firing event w/system.err( 809): java.lang.classnotfoundexception: com.sun.webkit.nativewebview w/system.err( 809): @ java.lang.class.classforname(native method) w/system.err( 809): @ java.lang.class.forname(class.java:309) w/system.err( 809): @ com.oracle.dalvik.internalwebview._fireloadevent(internalwebview.java:347) w/system.err( 809): @ com.oracle.dalvik.internalwebview.fireloadevent(internalwebview.java:140) w/system.err( 809): @ com.oracle.dalvik.internalwebview.access$400(internalwebview.java:43) w/system.err( 809): @ com.oracle.dalvik.internalwebview$myjavascriptinterface.processhtml(internalwebview.java:363) w/system.err( 809): @ org.chromium.base.systemmessagehandler.nativedorunlooponce(native method) w/system.err( 809): @ org.chromium.base.systemmessagehandler.handlemessage(systemmessagehandler.java:39) w/system.err( 809): @ android.os.handler.dispatchmessage(handler.java:102) w/system.err( 809): @ android.os.looper.loop(looper.java:145) w/system.err( 809): @ android.os.handlerthread.run(handlerthread.java:61) w/system.err( 809): caused by: java.lang.classnotfoundexception: didn't find class "com.sun.webkit.nativewebview" on path: dexpathlist[[directory "."],nativelibrarydirectories=[/vendor/lib, /system/lib]] w/system.err( 809): @ dalvik.system.basedexclassloader.findclass(basedexclassloader.java:56) w/system.err( 809): @ java.lang.classloader.loadclass(classloader.java:511) w/system.err( 809): @ java.lang.classloader.loadclass(classloader.java:469) w/system.err( 809): ... 11 more w/system.err( 809): suppressed: java.lang.classnotfoundexception: com.sun.webkit.nativewebview w/system.err( 809): @ java.lang.class.classforname(native method) w/system.err( 809): @ java.lang.bootclassloader.findclass(classloader.java:781) w/system.err( 809): @ java.lang.bootclassloader.loadclass(classloader.java:841) w/system.err( 809): @ java.lang.classloader.loadclass(classloader.java:504) w/system.err( 809): ... 12 more w/system.err( 809): caused by: java.lang.noclassdeffounderror: class not found using boot class loader; no stack available e/androidruntime( 809): fatal exception: javafx application thread e/androidruntime( 809): process: com.sundaethepugapp, pid: 809 e/androidruntime( 809): java.lang.unsupportedoperationexception: not supported yet. e/androidruntime( 809): @ com.sun.webkit.webpage.executescript(webpage.java:153) e/androidruntime( 809): @ javafx.scene.web.webengine.executescript(webengine.java:860) e/androidruntime( 809): @ com.sundaethepugapp.sundaethepugcontroller$1.changed(sundaethepugcontroller.java:202) e/androidruntime( 809): @ com.sundaethepugapp.sundaethepugcontroller$1.changed(sundaethepugcontroller.java:200) e/androidruntime( 809): @ com.sun.javafx.binding.expressionhelper$singlechange.firevaluechangedevent(expressionhelper.java:182) e/androidruntime( 809): @ com.sun.javafx.binding.expressionhelper.firevaluechangedevent(expressionhelper.java:81) e/androidruntime( 809): @ javafx.beans.property.readonlyobjectwrapper$readonlypropertyimpl.firevaluechangedevent(readonlyobjectwrapper.java:176) e/androidruntime( 809): @ javafx.beans.property.readonlyobjectwrapper.firevaluechangedevent(readonlyobjectwrapper.java:142) e/androidruntime( 809): @ javafx.beans.property.objectpropertybase.markinvalid(objectpropertybase.java:112) e/androidruntime( 809): @ javafx.beans.property.objectpropertybase.set(objectpropertybase.java:146) e/androidruntime( 809): @ javafx.scene.web.webengine$loadworker.updatestate(webengine.java:1023) e/androidruntime( 809): @ javafx.scene.web.webengine$loadworker.dispatchloadevent(webengine.java:1134) e/androidruntime( 809): @ javafx.scene.web.webengine$loadworker.access$1000(webengine.java:1016) e/androidruntime( 809): @ javafx.scene.web.webengine$pageloadlistener.dispatchloadevent(webengine.java:1003) e/androidruntime( 809): @ com.sun.webkit.webpage.fireloadevent(webpage.java:251) e/androidruntime( 809): @ com.sun.webkit.nativewebview$1.run(nativewebview.java:100) e/androidruntime( 809): @ com.sun.javafx.application.platformimpl.lambda$null$155(platformimpl.java:295) e/androidruntime( 809): @ com.sun.javafx.application.platformimpl.access$lambda$18(platformimpl.java) e/androidruntime( 809): @ com.sun.javafx.application.platformimpl$$lambda$19.run(unknown source) e/androidruntime( 809): @ java.security.accesscontroller.doprivileged(accesscontroller.java:52) e/androidruntime( 809): @ com.sun.javafx.application.platformimpl.lambda$runlater$156(platformimpl.java:294) e/androidruntime( 809): @ com.sun.javafx.application.platformimpl.access$lambda$5(platformimpl.java) e/androidruntime( 809): @ com.sun.javafx.application.platformimpl$$lambda$6.run(unknown source) e/androidruntime( 809): @ com.sun.glass.ui.monocle.runnableprocessor.runloop(runnableprocessor.java:92) e/androidruntime( 809): @ com.sun.glass.ui.monocle.runnableprocessor.run(runnableprocessor.java:51) e/androidruntime( 809): @ java.lang.thread.run(thread.java:818) v/applicationpolicy( 3468): isapplicationstateblocked userid 0 pkgname com.sundaethepugapp v/applicationpolicy( 3468): isapplicationstateblocked userid 0 pkgname com.sundaethepugapp v/applicationpolicy( 3468): isapplicationstateblocked userid 0 pkgname com.sec.android.app.launcher
what can alleviate , keep androids webview happy?
based on latest information provided, have 2 known issues:
media
if have @ this, media not supported yet, you'll need take out.
url scheme error
if have @ url
showed error message, jar:file:/data/.../base.apk!/googlelondonmap.html
, net::err_unknown_url_scheme
means jar:file
not known protocol on android.
the reason loading html file jar file not supported android sdk.
anyhow, resource accessible, workaround, load html file string , provide webengine
using method loadcontent
instead.
something should work:
stringwriter writer = new stringwriter(); bufferedreader reader = null; try { reader = new bufferedreader(new inputstreamreader(this.getclass().getresourceasstream("/googlelondonmap.html"))); string line = null; while ((line = reader.readline()) != null) { writer.append(line); } } catch (ioexception e) { e.printstacktrace(); } { if (reader != null) { try { reader.close(); } catch (ioexception e) { e.printstacktrace(); } } } engine.loadcontent(writer.tostring());
Comments
Post a Comment