关于android:不幸的是myapp已经停止了

Unfortunately myapp has stopped

本问题已经有最佳答案,请猛点这里访问。

我的申请已经停止了。项目将场景改为主应用到作业列表,但是,作业列表改为练习列表,?我正在Emulator上获取这些"不幸的是,应用程序已停止"。这是我的类。我也有致命的,除了?n在LogCAT上。

应用程序主.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;

    public class ApplicationMain extends Activity {
/** Called when the activity is first created. */
EditText nameEditCtrl;
Button btnCtlr;
String name;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    nameEditCtrl = (EditText) findViewById(R.id.editText1);
    btnCtlr = (Button) findViewById(R.id.button1);
    btnCtlr.setOnClickListener(new ButtonClickHandler());
}

public class ButtonClickHandler implements View.OnClickListener {
    public void onClick(View view) {
        if (nameEditCtrl != null && nameEditCtrl.getText().length() != 0) {
            name = nameEditCtrl.getText().toString();
        } else {
            name ="Guest";
        }
        Intent intObj = new Intent(ApplicationMain.this,
                JobList.class);
        intObj.putExtra("USERNAME", name);
        startActivity(intObj);
    }
}
 }

乔布斯

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.ImageButton;
    import android.widget.TextView;

    public class JobList extends Activity {
TextView greetMsg;
ImageButton ib;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.joblist);
    greetMsg = (TextView) findViewById(R.id.textView1);
    Intent intename = getIntent();
    String uname = (String) intename.getSerializableExtra("USERNAME");
    greetMsg.setText("Welcome" + uname);



    ib = (ImageButton) findViewById(R.id.imageButton1);
    ib.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intObj = new Intent(JobList.this,ExerciseList.class);
            startActivity(intObj);
        }
    });





    }

}

Java语言

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
      import android.app.Activity;
      import android.content.Intent;
      import android.os.Bundle;
      import android.view.View;
      import android.widget.Button;
      import android.widget.EditText;
      import android.widget.ImageButton;
      import android.widget.TextView;


     public class ExerciseList extends Activity {

ImageButton iz;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.exerciselist);

    iz = (ImageButton) findViewById(R.id.imageButton2);
        iz.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            Intent intObj = new Intent(ExerciseList.this,
                    ApplicationMain.class);
            //intObj.putExtra("USERNAME", name);
            startActivity(intObj);
        }
    });


}
 }

安卓宣言

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.prgguru.android"
android:versionCode="1"
android:versionName="1.0">


<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name">
    <activity
        android:name=".ApplicationMain"
        android:label="@string/app_name">
        <intent-filter>
           

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".JobList"
        android:label="@string/app_name">
    </activity>
</application>

     </manifest>


您忘记在manifest.xml中注册您的活动

1
2
3
4
<activity
        android:name=".ExerciseList"
        android:label="@string/app_name">
    </activity>