首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android应用程序崩溃,为什么?

Android应用程序崩溃,为什么?
EN

Stack Overflow用户
提问于 2012-12-11 07:46:35
回答 1查看 629关注 0票数 0

我试图创建一个简单的Android应用程序,将有可能获取一个网站的源代码。无论如何,我写了以下内容:

代码语言:javascript
复制
WebView webView = (WebView) findViewById(R.id.webView);
try {
    webView.setWebViewClient(new WebViewClient());          
    InputStream input = (InputStream) new URL(url.toString()).getContent();
    webView.loadDataWithBaseURL("", "<html><body><p>"+input.toString()+"</p></body></html>", "text/html", Encoding.UTF_8.toString(),""); 
    //setContentView(webView);
} catch (Exception e) {
    Alert alert = new Alert(getApplicationContext(),
                            "Error fetching data", e.getMessage());
}

以下是错误:

代码语言:javascript
复制
12-11 01:37:59.234: E/AndroidRuntime(28992): FATAL EXCEPTION: main
12-11 01:37:59.234: E/AndroidRuntime(28992): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
12-11 01:37:59.234: E/AndroidRuntime(28992):    at android.view.ViewRootImpl.setView(ViewRootImpl.java:701)
12-11 01:37:59.234: E/AndroidRuntime(28992):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:345)
12-11 01:37:59.234: E/AndroidRuntime(28992):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
12-11 01:37:59.234: E/AndroidRuntime(28992):    at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
12-11 01:37:59.234: E/AndroidRuntime(28992):    at android.app.Dialog.show(Dialog.java:277)
12-11 01:37:59.234: E/AndroidRuntime(28992):    at com.myprogram.myprogram.Alert.<init>(Alert.java:11)
12-11 01:37:59.234: E/AndroidRuntime(28992):    at com.myprogram.myprogram.MainActivity$1.onClick(MainActivity.java:84)
12-11 01:37:59.234: E/AndroidRuntime(28992):    at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
12-11 01:37:59.234: E/AndroidRuntime(28992):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-11 01:37:59.234: E/AndroidRuntime(28992):    at android.os.Looper.loop(Looper.java:137)
12-11 01:37:59.234: E/AndroidRuntime(28992):    at android.app.ActivityThread.main(ActivityThread.java:4898)
12-11 01:37:59.234: E/AndroidRuntime(28992):    at java.lang.reflect.Method.invokeNative(Native Method)
12-11 01:37:59.234: E/AndroidRuntime(28992):    at java.lang.reflect.Method.invoke(Method.java:511)
12-11 01:37:59.234: E/AndroidRuntime(28992):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
12-11 01:37:59.234: E/AndroidRuntime(28992):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
12-11 01:37:59.234: E/AndroidRuntime(28992):    at dalvik.system.NativeStart.main(Native Method)
12-11 01:38:21.484: I/Process(28992): Sending signal. PID: 28992 SIG: 9
12-11 01:38:32.739: E/Trace(29922): error opening trace file: No such file or directory (2)
12-11 01:38:32.939: I/webclipboard(29922): clipservice: android.sec.clipboard.ClipboardExManager@42209de8
12-11 01:38:32.964: V/webkit(29922): BrowserFrame constructor: this=Handler (android.webkit.BrowserFrame) {42204f18}

我似乎找不到解决方案,我的问题出在哪里?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-11 07:57:46

尝试一下:使用this代替getApplicationContext()

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13811282

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档