0
我遵循在我的應用程序的onCreate方法中定義Thread.setDefaultUncaughtExceptionHandler的方法。這個應用程序也在清單中定義。處理程序也被創建,但它的處理程序從來沒有被調用過,雖然我在LogCat中看到了一個JavaScript錯誤。Android WebView:異常未捕獲
12-19 03:02:58.630: I/chromium(1569): [INFO:CONSOLE(45)] "Uncaught ReferenceError: $contactArea is not defined", source: file:///android_asset/DefaultPage.html (45)
處理程序在我的應用程序定義:
public class HPAWebView extends Application {
private static Context context;
@Override
public void onCreate() {
super.onCreate();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, final Throwable ex) {
// Custom code here to handle the error.
Toast.makeText(HPAWebView.getAppContext(), "Oh no! " + ex.getMessage(), Toast.LENGTH_SHORT).show();
}
});
HPAWebView.context = getApplicationContext();
}
public static Context getAppContext() {
return HPAWebView.context;
}
}
...並且該申請在清單中表示:
<application
android:name="sap.com.prototype.webview.HPAWebView"