我正在尝试构建一个应用程序,在应用程序启动时在Android浏览器中打开网页。它工作正常除了网页开始加载后我得到这个“不幸的应用程序停止”消息但页面继续加载,我可以点击消息上的“确定”,它消失,浏览器保持打开页面我可以按预期使用它。如何才能让该消息停止弹出?
这是logcat
01-28 10:27:01.399: E/Trace(15226): error opening trace file: No such file or directory (2)
01-28 10:27:01.509: D/AndroidRuntime(15226): Shutting down VM
01-28 10:27:01.509: W/dalvikvm(15226): threadid=1: thread exiting with uncaught exception (group=0x41b702a0)
01-28 10:27:01.509: E/AndroidRuntime(15226): FATAL EXCEPTION: main
01-28 10:27:01.509: E/AndroidRuntime(15226): android.app.SuperNotCalledException: Activity {com.sugarray.nasamobile/com.sugarray.nasamobile.MainActivity} did not call through to super.onCreate()
01-28 10:27:01.509: E/AndroidRuntime(15226): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2102)
01-28 10:27:01.509: E/AndroidRuntime(15226): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2174)
01-28 10:27:01.509: E/AndroidRuntime(15226): at android.app.ActivityThread.access$700(ActivityThread.java:141)
01-28 10:27:01.509: E/AndroidRuntime(15226): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1267)
01-28 10:27:01.509: E/AndroidRuntime(15226): at android.os.Handler.dispatchMessage(Handler.java:99)
01-28 10:27:01.509: E/AndroidRuntime(15226): at android.os.Looper.loop(Looper.java:137)
01-28 10:27:01.509: E/AndroidRuntime(15226): at android.app.ActivityThread.main(ActivityThread.java:5059)
01-28 10:27:01.509: E/AndroidRuntime(15226): at java.lang.reflect.Method.invokeNative(Native Method)
01-28 10:27:01.509: E/AndroidRuntime(15226): at java.lang.reflect.Method.invoke(Method.java:511)
01-28 10:27:01.509: E/AndroidRuntime(15226): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
01-28 10:27:01.509: E/AndroidRuntime(15226): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
01-28 10:27:01.509: E/AndroidRuntime(15226): at dalvik.system.NativeStart.main(Native Method)
01-28 10:28:48.009: I/Process(15226): Sending signal. PID: 15226 SIG: 9
01-28 10:34:26.813: E/Trace(15569): error opening trace file: No such file or directory (2)
01-28 10:34:26.907: D/AndroidRuntime(15569): Shutting down VM
01-28 10:34:26.907: W/dalvikvm(15569): threadid=1: thread exiting with uncaught exception (group=0x41b702a0)
01-28 10:34:26.915: E/AndroidRuntime(15569): FATAL EXCEPTION: main
01-28 10:34:26.915: E/AndroidRuntime(15569): android.app.SuperNotCalledException: Activity {com.sugarray.nasamobile/com.sugarray.nasamobile.MainActivity} did not call through to super.onCreate()
01-28 10:34:26.915: E/AndroidRuntime(15569): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2102)
01-28 10:34:26.915: E/AndroidRuntime(15569): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2174)
01-28 10:34:26.915: E/AndroidRuntime(15569): at android.app.ActivityThread.access$700(ActivityThread.java:141)
01-28 10:34:26.915: E/AndroidRuntime(15569): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1267)
01-28 10:34:26.915: E/AndroidRuntime(15569): at android.os.Handler.dispatchMessage(Handler.java:99)
01-28 10:34:26.915: E/AndroidRuntime(15569): at android.os.Looper.loop(Looper.java:137)
01-28 10:34:26.915: E/AndroidRuntime(15569): at android.app.ActivityThread.main(ActivityThread.java:5059)
01-28 10:34:26.915: E/AndroidRuntime(15569): at java.lang.reflect.Method.invokeNative(Native Method)
01-28 10:34:26.915: E/AndroidRuntime(15569): at java.lang.reflect.Method.invoke(Method.java:511)
01-28 10:34:26.915: E/AndroidRuntime(15569): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
01-28 10:34:26.915: E/AndroidRuntime(15569): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
01-28 10:34:26.915: E/AndroidRuntime(15569): at dalvik.system.NativeStart.main(Native Method)
MainActivity
package com.sugarray.nasamobile;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
Uri uriUrl = Uri.parse("http://mobile.nasa.gov");
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
}
public void exit(View view){
System.exit(0);
}
}
答案 0 :(得分:4)
只需将此行添加到onCreate()
的开头:
super.onCreate(savedInstanceState);
PS:您应该学会阅读日志。他们确实已经包含了解决方案。
答案 1 :(得分:1)
读取堆栈跟踪。它说:
android.app.SuperNotCalledException: Activity
{com.sugarray.nasamobile/com.sugarray.nasamobile.MainActivity} did not call through to super.onCreate()
您忘记拨打super.onCreate()
,因为FD_已经指出了。根据经验,大多数Android方法都需要您调用超级方法,尤其是生命周期中的方法。
注意:堆栈痕迹是供人类阅读的,并不是一些音译为英语的外星手语。 LOL