Android MyFirstApp - 遗憾的是应用程序停止运行

时间:2014-10-10 07:06:19

标签: java android

我按照http://developer.android.com/training/basics/firstapp/starting-activity.html#AddToManifest

中提到的提示在android中设计了第一个应用程序

当我输入内容并按“发送”按钮时,它会显示“不幸的应用停止工作” 相应的日志如下

10-10 12:10:04.029: D/dalvikvm(550): Not late-enabling CheckJNI (already on)
10-10 12:10:06.549: D/gralloc_goldfish(550): Emulator without GPU emulation detected.
10-10 12:10:26.169: D/AndroidRuntime(550): Shutting down VM
10-10 12:10:26.169: W/dalvikvm(550): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
10-10 12:10:26.229: E/AndroidRuntime(550): FATAL EXCEPTION: main
10-10 12:10:26.229: E/AndroidRuntime(550): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.DisplayMessageActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f080000 for fragment PlaceholderFragment{4108e7c8 #0 id=0x7f080000}
10-10 12:10:26.229: E/AndroidRuntime(550):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
10-10 12:10:26.229: E/AndroidRuntime(550):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
10-10 12:10:26.229: E/AndroidRuntime(550):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
10-10 12:10:26.229: E/AndroidRuntime(550):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
10-10 12:10:26.229: E/AndroidRuntime(550):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-10 12:10:26.229: E/AndroidRuntime(550):  at android.os.Looper.loop(Looper.java:137)
10-10 12:10:26.229: E/AndroidRuntime(550):  at android.app.ActivityThread.main(ActivityThread.java:4340)
10-10 12:10:26.229: E/AndroidRuntime(550):  at java.lang.reflect.Method.invokeNative(Native Method)
10-10 12:10:26.229: E/AndroidRuntime(550):  at java.lang.reflect.Method.invoke(Method.java:511)
10-10 12:10:26.229: E/AndroidRuntime(550):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-10 12:10:26.229: E/AndroidRuntime(550):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-10 12:10:26.229: E/AndroidRuntime(550):  at dalvik.system.NativeStart.main(Native Method)
10-10 12:10:26.229: E/AndroidRuntime(550): Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f080000 for fragment PlaceholderFragment{4108e7c8 #0 id=0x7f080000}
10-10 12:10:26.229: E/AndroidRuntime(550):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:789)
10-10 12:10:26.229: E/AndroidRuntime(550):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:998)
10-10 12:10:26.229: E/AndroidRuntime(550):  at android.app.BackStackRecord.run(BackStackRecord.java:622)
10-10 12:10:26.229: E/AndroidRuntime(550):  at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1330)
10-10 12:10:26.229: E/AndroidRuntime(550):  at android.app.Activity.performStart(Activity.java:4474)
10-10 12:10:26.229: E/AndroidRuntime(550):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1928)
10-10 12:10:26.229: E/AndroidRuntime(550):  ... 11 more
10-10 12:10:31.099: I/Process(550): Sending signal. PID: 550 SIG: 9

代码:

public void sendMessage(View view) { 
   Intent intent=new Intent(this, DisplayMessageActivity.class); 
   EditText editText=(EditText)findViewById(R.id.edit_message); 
   String message=editText.toString().toString(); 
   intent.putExtra(EXTRA_MESSAGE, message); 
   startActivity(intent); 
}

DisplayMessageActivity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_message);
    if (savedInstanceState == null) {
        getFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }
    Intent intent=getIntent();
    String message=intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

    TextView textView=new TextView(this);
    textView.setTextSize(40);
    textView.setText(message);

    setContentView(textView);
}

问题是什么? Plz建议我

2 个答案:

答案 0 :(得分:0)

我查看了您在此处粘贴的链接,我认为这可以解决您的问题:

在您的 activity_display_message.xml 中,您必须添加以下代码

android:id="@+id/activity_display_message

答案 1 :(得分:-3)

在Android SDK Tools R15中,您可以启用GPU模拟。

您需要创建一个新的仿真器虚拟设备,并在硬件属性中将GPU仿真设置为true。

现在可以直接通过Emulator Creation选项启用GPU启用。转到Window - > Android虚拟设备管理器 - >现在记得要检查标记"使用GPU主机"然后你将拥有相当快速工作的模拟器和GPU启用。