私はphonegapを使用して、Android2.3.3環境のJavaスクリプトからJava関数を呼び出そうとする1つのアプリをプログラムしていました。
私の問題は、アプリがアラートメッセージを表示してからクラッシュし、以下のエラーメッセージが表示されることでした
08-04 11:06:12.669: W/dalvikvm(551): JNI WARNING: jarray 0x40522898 points to non-array object (Ljava/lang/String;)
08-04 11:06:12.669: I/dalvikvm(551): "WebViewCoreThread" prio=5 tid=9 NATIVE
08-04 11:06:12.669: I/dalvikvm(551): | group="main" sCount=0 dsCount=0 obj=0x4051dd20 self=0x2a6d88
08-04 11:06:12.669: I/dalvikvm(551): | sysTid=559 nice=0 sched=0/0 cgrp=default handle=2780864
08-04 11:06:12.669: I/dalvikvm(551): | schedstat=( 943171212 746714576 110 )
08-04 11:06:12.680: I/dalvikvm(551): at android.webkit.WebViewCore.nativeTouchUp(Native Method)
08-04 11:06:12.680: I/dalvikvm(551): at android.webkit.WebViewCore.nativeTouchUp(Native Method)
08-04 11:06:12.680: I/dalvikvm(551): at android.webkit.WebViewCore.access$3300(WebViewCore.java:53)
08-04 11:06:12.680: I/dalvikvm(551): at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1158)
08-04 11:06:12.680: I/dalvikvm(551): at android.os.Handler.dispatchMessage(Handler.java:99)
08-04 11:06:12.680: I/dalvikvm(551): at android.os.Looper.loop(Looper.java:123)
08-04 11:06:12.680: I/dalvikvm(551): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:629)
08-04 11:06:12.680: I/dalvikvm(551): at java.lang.Thread.run(Thread.java:1019)
08-04 11:06:12.680: E/dalvikvm(551): VM aborting
誰かがこの問題について助け/アドバイスできますか?
以下はコードです
MainActivity.java
import org.apache.cordova.*;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
public class MainActivity extends DroidGap {
private MyClass mc;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
mc = new MyClass(this, appView);
appView.addJavascriptInterface(mc, "MyCls");
super.loadUrl("file:///android_asset/www/5.html");
}
}
MyClass.java
import org.apache.cordova.DroidGap;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.webkit.WebView;
public class MyClass {
private WebView mAppView;
private DroidGap mGap;
public MyClass(DroidGap gap, WebView view)
{
mAppView = view;
mGap = gap;
System.out.println("jjjjj");
}
public String getTelephoneNumber(){
return "i am android";
}
}
5.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="jquery.jsonp.js"></script>
</head>
<script>
$(document).ready(function(){
$("#c2").click(function(){
alert('jjjj');
var t = window.MyCls.getTelephoneNumber();
alert(t );
});
});
</script>
<body>
<br><button id="c2">Call Android Activity</button>
</body>
</html>
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:resizeable="true"
android:anyDensity="true" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:configChanges="orientation|keyboardHidden|screenSize"
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="MainActivity" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>