【发布时间】:2012-01-19 16:21:59
【问题描述】:
在我的 Android 应用中,WebView 活动类具有以下行,
webView.addJavascriptInterface(new JSInterface(this), "Android");
在 JSInterface 类中,我正在初始化 Google“SpreadSheetService”,如下所示,
import com.google.gdata.client.spreadsheet.SpreadsheetService;
--- some more imports ---
public class JSInterface {
Context mContext;
public SpreadsheetService service;
/** Instantiate the interface and set the context */
JSInterface(Context c) {
mContext = c;
service = new SpreadsheetService("List Demo");
}
------- some more code -----
当我运行应用程序时,出现以下异常,
01-19 21:38:00.652: E/AndroidRuntime(4085): java.lang.ExceptionInInitializerError
有以下痕迹
01-19 21:38:00.652: E/AndroidRuntime(4085): FATAL EXCEPTION: main
01-19 21:38:00.652: E/AndroidRuntime(4085): java.lang.ExceptionInInitializerError
01-19 21:38:00.652: E/AndroidRuntime(4085): at com.android.quotes.JSInterface.<init>(JSInterface.java:33)
01-19 21:38:00.652: E/AndroidRuntime(4085): at com.android.quotes.CHQuotesActivity.onCreate(CHQuotesActivity.java:19)
01-19 21:38:00.652: E/AndroidRuntime(4085): at android.app.Activity.performCreate(Activity.java:4465)
01-19 21:38:00.652: E/AndroidRuntime(4085): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-19 21:38:00.652: E/AndroidRuntime(4085): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
01-19 21:38:00.652: E/AndroidRuntime(4085): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
01-19 21:38:00.652: E/AndroidRuntime(4085): at android.app.ActivityThread.access$600(ActivityThread.java:122)
01-19 21:38:00.652: E/AndroidRuntime(4085): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
01-19 21:38:00.652: E/AndroidRuntime(4085): at android.os.Handler.dispatchMessage(Handler.java:99)
01-19 21:38:00.652: E/AndroidRuntime(4085): at android.os.Looper.loop(Looper.java:137)
01-19 21:38:00.652: E/AndroidRuntime(4085): at android.app.ActivityThread.main(ActivityThread.java:4340)
01-19 21:38:00.652: E/AndroidRuntime(4085): at java.lang.reflect.Method.invokeNative(Native Method)
01-19 21:38:00.652: E/AndroidRuntime(4085): at java.lang.reflect.Method.invoke(Method.java:511)
我搜索了谷歌,但没有得到任何解决方案。知道为什么我会收到这个异常吗?
彼得
【问题讨论】:
-
是否可以在代码中的任何位置创建 asyncTask/Handler?
-
似乎 trace 仅显示
exception发生的位置。但没有显示它是什么原因造成的,从异常中找到这一行Caused by:。检查导致错误的行。
标签: android android-webview google-spreadsheet-api