與此question類似,但解決方案在mycase中不起作用。Android應用程序在webview url更改時崩潰
E/AndroidRuntime(1593):: java.lang.Throwable中:警告:致運行功能webview.loadUrl
時獲取有關接近以下錯誤Android應用崩潰網頁視圖方法在線程 'WebViewCoreThread'上被調用。必須在UI 線程上調用所有WebView方法。未來版本的WebView可能不支持其他 線程的使用。
編輯:現在嘗試在runOnUiThread(new Runnable(){})中運行函數,但獲取錯誤並遇到在上下文中輸入runOnUiThread的位置的問題。
這裏是全碼:
public class MyJavaScriptInterface {
@JavascriptInterface
public void androidFieldPrompt(String title, String msg, final String funct) {
final EditText input = new EditText(MainActivity.this);
AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
alert.setTitle(title);
alert.setMessage(msg);
alert.setView(input);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString();
// ERROR IS BEING THROWN HERE
webView.loadUrl("javascript:window."+funct+"('"+value+"')");
return;
}
});
alert.show();
}
}
[WebView方法不可能在Android中調用]的可能的重複(http://stackoverflow.com/questions/17944347/webview-methods-is-not-called-in-android) – CRUSADER