我试图让我的 Android 应用程序中的浏览器功能正常工作,但应用程序在加载时崩溃。这是加载新活动时的代码:
@Override
public void onCreate(Bundle savedInstanceState) {
WebView webview = new WebView(this);
setContentView(webview);
webview.loadUrl("http://erik-edgren.nu/weather");
getWindow().requestFeature(Window.FEATURE_PROGRESS);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
}
这是 LogCat:
04-05 13:51:20.224: D/dalvikvm(742): GC freed 2673 objects / 169288 bytes in 107ms
04-05 13:51:20.354: D/AndroidRuntime(742): Shutting down VM
04-05 13:51:20.354: W/dalvikvm(742): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-05 13:51:20.364: E/AndroidRuntime(742): Uncaught handler: thread main exiting due to uncaught exception
04-05 13:51:20.373: E/AndroidRuntime(742): java.lang.RuntimeException: Unable to start activity ComponentInfo{weather.right.now/weather.right.Browser}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
04-05 13:51:20.373: E/AndroidRuntime(742): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-05 13:51:20.373: E/AndroidRuntime(742): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-05 13:51:20.373: E/AndroidRuntime(742): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-05 13:51:20.373: E/AndroidRuntime(742): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-05 13:51:20.373: E/AndroidRuntime(742): at android.os.Handler.dispatchMessage(Handler.java:99)
04-05 13:51:20.373: E/AndroidRuntime(742): at android.os.Looper.loop(Looper.java:123)
04-05 13:51:20.373: E/AndroidRuntime(742): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-05 13:51:20.373: E/AndroidRuntime(742): at java.lang.reflect.Method.invokeNative(Native Method)
04-05 13:51:20.373: E/AndroidRuntime(742): at java.lang.reflect.Method.invoke(Method.java:521)
04-05 13:51:20.373: E/AndroidRuntime(742): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-05 13:51:20.373: E/AndroidRuntime(742): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-05 13:51:20.373: E/AndroidRuntime(742): at dalvik.system.NativeStart.main(Native Method)
04-05 13:51:20.373: E/AndroidRuntime(742): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
04-05 13:51:20.373: E/AndroidRuntime(742): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:172)
04-05 13:51:20.373: E/AndroidRuntime(742): at weather.right.Browser.onCreate(Browser.java:23)
04-05 13:51:20.373: E/AndroidRuntime(742): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-05 13:51:20.373: E/AndroidRuntime(742): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-05 13:51:20.373: E/AndroidRuntime(742): ... 11 more
04-05 13:51:20.404: I/dalvikvm(742): threadid=7: reacting to signal 3
04-05 13:51:20.484: I/dalvikvm(742): Wrote stack trace to '/data/anr/traces.txt'
我该如何解决这个问题?
提前致谢。
编辑:新的 LogCat
04-05 14:00:40.893: D/dalvikvm(783): GC freed 2724 objects / 171288 bytes in 136ms
04-05 14:00:41.044: D/AndroidRuntime(783): Shutting down VM
04-05 14:00:41.064: W/dalvikvm(783): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-05 14:00:41.064: E/AndroidRuntime(783): Uncaught handler: thread main exiting due to uncaught exception
04-05 14:00:41.074: E/AndroidRuntime(783): android.app.SuperNotCalledException: Activity {weather.right.now/weather.right.Browser} did not call through to super.onCreate()
04-05 14:00:41.074: E/AndroidRuntime(783): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2461)
04-05 14:00:41.074: E/AndroidRuntime(783): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-05 14:00:41.074: E/AndroidRuntime(783): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-05 14:00:41.074: E/AndroidRuntime(783): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-05 14:00:41.074: E/AndroidRuntime(783): at android.os.Handler.dispatchMessage(Handler.java:99)
04-05 14:00:41.074: E/AndroidRuntime(783): at android.os.Looper.loop(Looper.java:123)
04-05 14:00:41.074: E/AndroidRuntime(783): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-05 14:00:41.074: E/AndroidRuntime(783): at java.lang.reflect.Method.invokeNative(Native Method)
04-05 14:00:41.074: E/AndroidRuntime(783): at java.lang.reflect.Method.invoke(Method.java:521)
04-05 14:00:41.074: E/AndroidRuntime(783): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-05 14:00:41.074: E/AndroidRuntime(783): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-05 14:00:41.074: E/AndroidRuntime(783): at dalvik.system.NativeStart.main(Native Method)
04-05 14:00:41.094: I/dalvikvm(783): threadid=7: reacting to signal 3
04-05 14:00:41.124: I/dalvikvm(783): Wrote stack trace to '/data/anr/traces.txt'
04-05 14:00:43.176: I/Process(783): Sending signal. PID: 783 SIG: 9
04-05 14:00:43.994: D/LocationManager(798): Constructor: service = android.location.ILocationManager$Stub$Proxy@44e95780