I am trying to reproduce a very simple example from Apache Cordova's Plugin Development Guide. The sample HTML JavaScript does not seem to be executing beyond the call to the Android Java Plug in. Here is the Java Code that deploys to the Android Emulator successfully and opens index.html:
MainActivity.java
| Code: |
package com.essentialsoftware.testbump;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import org.apache.cordova.*;
public class MainActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}
|
Here is the java plugin:
Echo.java
| Code: |
package com.essentialsoftware.testbump;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* This class echoes a string called from JavaScript.
*/
public class Echo extends Plugin {
/**
* Executes the request and returns PluginResult.
*
* @param action The action to execute.
* @param args JSONArry of arguments for the plugin.
* @param callbackId The callback id used when calling back into JavaScript.
* @return A PluginResult object with a status and message.
*/
public PluginResult execute(String action, JSONArray args, String callbackId) {
try {
if (action.equals("echo")) {
String echo = args.getString(0);
if (echo != null && echo.length() > 0) {
return new PluginResult(PluginResult.Status.OK, echo);
} else {
return new PluginResult(PluginResult.Status.ERROR);
}
} else {
return new PluginResult(PluginResult.Status.INVALID_ACTION);
}
} catch (JSONException e) {
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}
}
|
Here is the web page that invokes Echo:
index.html
| Code: |
<!DOCTYPE HTML>
<html>
<head>
<title>Cordova</title>
<script src="cordova-2.0.0.js"></script>
</head>
<body>
<h1 id="demo">Hello World</h1>
<script type="text/javascript">
document.getElementById("demo").innerHTML="Before function declaration";
window.echo = function(str, callback) {
cordova.exec(callback, function(err) {
callback('Nothing to echo.');
}, "Echo", "echo", [str]);
};
document.getElementById("demo").innerHTML="After function declaration";
window.echo("echome", function(echoValue) {
alert(echoValue == "echome"); // should alert true.
});
document.getElementById("demo").innerHTML="After function invocation";
alert("hello" == "Goodbye");
document.getElementById("demo").innerHTML="Test2";
</script>
</body>
</html>
|
When index.html opens in the android emulator it displays
After function declaration
If I am correct, this means the JavaScript is erroring out in
| Code: |
window.echo("echome", function(echoValue) {
alert(echoValue == "echome"); // should alert true.
});
|
Any advice as to what I am doing wrong? Any tips for debugging the JavaScript or my Andriod Java Code?
Here is my installation summary and my error log.
Installation Summary:
*** Date:
Thursday, August 30, 2012 12:02:41 AM MDT
*** System properties:
OS=WindowsVista
OS version=6.1.0
OS arch=x86
Profile arch=x86
Window system=win32
Java version=1.6.0_13
Workspace=file:/C:/Users/sgray/Documents/Workspaces/
VM Args=-Xmx512m
-XX:MaxPermSize=256m
-XX:ReservedCodeCacheSize=64m
-Dosgi.nls.warnings=ignore
-Djava.class.path=C:\Users\sgray\AppData\Local\MYECLI~1\MYECLI~1\../Common/plugins/ORB7B5~1.JAR
*** Subscription information
Product Id: E3MP (MyEclipse Professional Subscription)
License version: 3.0
Full Maintenance Included
Subscription expiration date (YYYYMMDD): 20130715
Number of users: 1
*** Eclipse details:
MyEclipse Enterprise Workbench
Version: 10.6
Build id: 10.6-20120727
Blueprint: MyEclipse 10
com.genuitec.myeclipse.database - 10.6.0.me201207261914
com.genuitec.myeclipse.desktop - 10.6.0.me201207261914
com.genuitec.myeclipse.editor - 10.6.0.me201207261914
com.genuitec.myeclipse.enterprise.workbench - 10.6.0.me201207261914
com.genuitec.myeclipse.geronimo - 10.6.0.me201207261914
com.genuitec.myeclipse.glassfish - 10.6.0.me201207261914
com.genuitec.myeclipse.icefaces.feature - 10.6.0.me201207261914
com.genuitec.myeclipse.iedebugger - 10.6.0.me201207261914
com.genuitec.myeclipse.imageeditor - 10.6.0.me201207261914
com.genuitec.myeclipse.jboss - 10.6.0.me201207261914
com.genuitec.myeclipse.jetty - 10.6.0.me201207261914
com.genuitec.myeclipse.jonas - 10.6.0.me201207261914
com.genuitec.myeclipse.jrun - 10.6.0.me201207261914
com.genuitec.myeclipse.jsf - 10.6.0.me201207261914
com.genuitec.myeclipse.matisse - 10.6.0.me201207261914
com.genuitec.myeclipse.maven - 10.6.0.me201207261914
com.genuitec.myeclipse.oracle - 10.6.0.me201207261914
com.genuitec.myeclipse.orion - 10.6.0.me201207261914
com.genuitec.myeclipse.persistence - 10.6.0.me201207261914
com.genuitec.myeclipse.pulse - 10.6.0.me201207261914
com.genuitec.myeclipse.reports - 10.6.0.me201207261914
com.genuitec.myeclipse.resin - 10.6.0.me201207261914
com.genuitec.myeclipse.struts - 10.6.0.me201207261914
com.genuitec.myeclipse.sun - 10.6.0.me201207261914
com.genuitec.myeclipse.tomcat - 10.6.0.me201207261914
com.genuitec.myeclipse.uml2 - 10.6.0.me201207261914
com.genuitec.myeclipse.visualvm - 10.6.0.me201207261914
com.genuitec.myeclipse.visualvm.server - 10.6.0.me201207261914
com.genuitec.myeclipse.weblogic - 10.6.0.me201207261914
com.genuitec.myeclipse.websphere - 10.6.0.me201207261914
com.genuitec.myeclipse.ws - 10.6.0.me201207261914
org.eclipse.birt - 2.6.1.me201207261914
org.eclipse.datatools.connectivity.feature - 1.9.0.me201207261914
org.eclipse.datatools.enablement.feature - 1.9.0.me201207261914
org.eclipse.datatools.modelbase.feature - 1.9.0.v201106031100-77078CcNBHCBYKYEbNV
org.eclipse.datatools.sqldevtools.feature - 1.9.0.me201207261914
org.eclipse.emf - 2.7.0.v20110606-0949
org.eclipse.gef - 3.7.0.v20110425-2050-777D-81B2Bz0685C3A6E34272
org.eclipse.graphiti.feature - 0.8.0.v20110607-1252
org.eclipse.jpt.jpa.feature - 3.0.0.me201207261914
org.eclipse.jpt.jpadiagrameditor.feature - 1.0.0.me201207261914
org.eclipse.jst.common.fproj.enablement.jdt - 3.3.0.me201207261914
org.eclipse.jst.enterprise_ui.feature - 3.3.0.me201207261914
org.eclipse.jst.server_adapters.ext.feature - 3.3.0.me201207261914
org.eclipse.jst.server_adapters.feature - 3.2.100.me201207261914
org.eclipse.jst.server_ui.feature - 3.3.0.me201207261914
org.eclipse.jst.ws.axis2tools.feature - 1.1.200.me201207261914
org.eclipse.m2e.feature - 1.0.0.me201207261914
org.eclipse.sapphire.platform - 0.3.0.201106221325
org.eclipse.wst.common.fproj - 3.3.0.me201207261914
org.eclipse.wst.server_adapters.feature - 3.2.100.me201207261914
org.eclipse.xsd - 2.7.0.v20110606-0949
org.springframework.ide.eclipse.feature - 2.9.1.me201207261914
com.android.ide.eclipse.adt - 20.0.3.v201208082019-427395
com.android.ide.eclipse.ddms - 20.0.3.v201208082019-427395
com.android.ide.eclipse.hierarchyviewer - 20.0.3.v201208082019-427395
com.android.ide.eclipse.traceview - 20.0.3.v201208082019-427395
fr.obeo.acceleo.bridge.feature - 2.6.0.200906261742
org.eclipse.cvs - 1.3.100.v20110520-0800-7B78FHl9VF7BD7KBM4GP9C
org.eclipse.draw2d - 3.7.0.v20110425-2050-46-7w3122153603161
org.eclipse.equinox.p2.core.feature - 1.0.1.v20110906-1605-8290FZ9FVKHVRKtmx3fpNuo02129
org.eclipse.equinox.p2.extras.feature - 1.0.1.v20110906-1605-7A4FD4DiVOMap8cHSc6vPuny4gqO
org.eclipse.equinox.p2.rcp.feature - 1.0.1.v20110906-1605-782EqBqNKGVkiV-PUsgz-uny4gqO
org.eclipse.equinox.p2.user.ui - 2.1.2.R37x_v20110815-1155-6-Bk8pYWZz0qUTX5I15GZWwbXkrl
org.eclipse.help - 1.3.0.v20110530-0844-7i7uFFmFFl8nvqbDpEqTvx
org.eclipse.jdt - 3.7.2.v20120120-1414-7z8gFcuFMP7BW5XTz0jLTnz0l9B1
org.eclipse.jsf.feature - 3.3.0.me201207261914
org.eclipse.ocl - 3.1.0.v20110606-1427
org.eclipse.pde - 3.7.2.v20120120-1420-7b7rFUOFEx2Xnqafnpz0E--0
org.eclipse.platform - 3.7.2.v20120207-1839-9gF7UHPDFxGjd-PqDr2jX_4yKaumkoHTz04_q-q
org.eclipse.rcp - 3.7.2.v20120120-1424-9DB5FmnFq5JCf1UA38R-kz0S0272
Eclipse startup command=-os
win32
-ws
win32
-arch
x86
-showsplash
-launcher
C:\Users\sgray\AppData\Local\MyEclipse\MyEclipse 10\myeclipse.exe
-name
Myeclipse
--launcher.library
C:\Users\sgray\AppData\Local\MyEclipse\MyEclipse 10\../Common/plugins/org.eclipse.equinox.launcher.i18n.win32.win32.x86_4.2.0.v201201111650\eclipse_4201.dll
-startup
C:\Users\sgray\AppData\Local\MyEclipse\MyEclipse 10\../Common/plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
-install
C:\Users\sgray\AppData\Local\MyEclipse\MyEclipse 10
-configuration
C:\Users\sgray\AppData\Local\MyEclipse\MyEclipse 10\configuration
-vm
C:\Users\sgray\AppData\Local\MyEclipse\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\bin\client\jvm.dll
Error Log:
!SESSION 2012-06-06 01:17:11.766 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_13
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Command-line arguments: -os win32 -ws win32 -arch x86
!ENTRY com.genuitec.eclipse.wizards 1 0 2012-06-06 01:18:04.208
!MESSAGE Installed snippet library: C:\Users\sgray.ESSENTIALSOFTWA\AppData\Local\MyEclipse\MyEclipse 10\configuration\org.eclipse.osgi\bundles8<!-- [\.cp\snippets\html\css_snippets.xml
!ENTRY com.genuitec.eclipse.wizards 1 0 2012-06-06 01:18:04.427
!MESSAGE Installed snippet library: C:\Users\sgray.ESSENTIALSOFTWA\AppData\Local\MyEclipse\MyEclipse 10\configuration\org.eclipse.osgi\bundles8<!-- [\.cp\snippets\html\forms_lists_snippets.xml
!ENTRY com.genuitec.eclipse.wizards 1 0 2012-06-06 01:18:04.505
!MESSAGE Installed snippet library: C:\Users\sgray.ESSENTIALSOFTWA\AppData\Local\MyEclipse\MyEclipse 10\configuration\org.eclipse.osgi\bundles8<!-- [\.cp\snippets\html\htmlform_snippets.xml
!ENTRY com.genuitec.eclipse.wizards 1 0 2012-06-06 01:18:04.598
!MESSAGE Installed snippet library: C:\Users\sgray.ESSENTIALSOFTWA\AppData\Local\MyEclipse\MyEclipse 10\configuration\org.eclipse.osgi\bundles8<!-- [\.cp\snippets\html\html_snippets.xml
!ENTRY com.genuitec.eclipse.wizards 1 0 2012-06-06 01:18:04.661
!MESSAGE Installed snippet library: C:\Users\sgray.ESSENTIALSOFTWA\AppData\Local\MyEclipse\MyEclipse 10\configuration\org.eclipse.osgi\bundles8<!-- [\.cp\snippets\html\javascript_snippets.xml
!ENTRY com.genuitec.eclipse.wizards 1 0 2012-06-06 01:18:04.723
!MESSAGE Installed snippet library: C:\Users\sgray.ESSENTIALSOFTWA\AppData\Local\MyEclipse\MyEclipse 10\configuration\org.eclipse.osgi\bundles8<!-- [\.cp\snippets\jsp\jsf_f_snippets.xml
!ENTRY com.genuitec.eclipse.wizards 1 0 2012-06-06 01:18:05.052
!MESSAGE Installed snippet library: C:\Users\sgray.ESSENTIALSOFTWA\AppData\Local\MyEclipse\MyEclipse 10\configuration\org.eclipse.osgi\bundles8<!-- [\.cp\snippets\jsp\jsf_h_snippets.xml
!ENTRY com.genuitec.eclipse.wizards 1 0 2012-06-06 01:18:05.114
!MESSAGE Installed snippet library: C:\Users\sgray.ESSENTIALSOFTWA\AppData\Local\MyEclipse\MyEclipse 10\configuration\org.eclipse.osgi\bundles8<!-- [\.cp\snippets\jsp\struts_bean_snippets.xml
!ENTRY com.genuitec.eclipse.wizards 1 0 2012-06-06 01:18:05.208
!MESSAGE Installed snippet library: C:\Users\sgray.ESSENTIALSOFTWA\AppData\Local\MyEclipse\MyEclipse 10\configuration\org.eclipse.osgi\bundles8<!-- [\.cp\snippets\jsp\struts_html_snippets.xml
!ENTRY com.genuitec.eclipse.wizards 1 0 2012-06-06 01:18:05.270
!MESSAGE Installed snippet library: C:\Users\sgray.ESSENTIALSOFTWA\AppData\Local\MyEclipse\MyEclipse 10\configuration\org.eclipse.osgi\bundles8<!-- [\.cp\snippets\jsp\struts_logic_snippets.xml
!ENTRY com.genuitec.eclipse.wizards 1 0 2012-06-06 01:18:05.364
!MESSAGE Installed snippet library: C:\Users\sgray.ESSENTIALSOFTWA\AppData\Local\MyEclipse\MyEclipse 10\configuration\org.eclipse.osgi\bundles8<!-- [\.cp\snippets\jsp\struts_tiles_snippets.xml
!ENTRY org.eclipse.osgi 2 0 2012-06-06 01:19:16.099
!MESSAGE While loading class "org.eclipse.wst.jsdt.internal.core.JavaModelManager$16", thread "Thread[Worker-8,5,main]" timed out waiting (5000ms) for thread "Thread[main,6,main]" to finish starting bundle "org.eclipse.wst.jsdt.core_1.1.100.me201203060843 [961]". To avoid deadlock, thread "Thread[Worker-8,5,main]" is proceeding but "org.eclipse.wst.jsdt.internal.core.JavaModelManager$16" may not be fully initialized.
!STACK 0
org.osgi.framework.BundleException: State change in progress for bundle "reference:file:/C:/Users/sgray.ESSENTIALSOFTWA/AppData/Local/MyEclipse/Common/plugins/org.eclipse.wst.jsdt.core_1.1.100.me201203060843.jar" by thread "main".
at org.eclipse.osgi.framework.internal.core.AbstractBundle.beginStateChange(AbstractBundle.java:1087)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:297)
at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:440)
at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:268)
at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:463)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:400)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:476)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at org.eclipse.wst.jsdt.internal.core.JavaModelManager$15.run(JavaModelManager.java:4182)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: org.eclipse.osgi.framework.internal.core.AbstractBundle$BundleStatusException
... 16 more
Root exception:
org.eclipse.osgi.framework.internal.core.AbstractBundle$BundleStatusException
at org.eclipse.osgi.framework.internal.core.AbstractBundle.beginStateChange(AbstractBundle.java:1087)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:297)
at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:440)
at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:268)
at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:463)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:400)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:476)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at org.eclipse.wst.jsdt.internal.core.JavaModelManager$15.run(JavaModelManager.java:4182)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
!ENTRY org.eclipse.core.jobs 2 2 2012-06-06 01:22:47.284
!MESSAGE Job found still running after platform shutdown. Jobs should be canceled by the plugin that scheduled them during shutdown: org.eclipse.m2e.core.internal.index.nexus.IndexUpdaterJob