我已經搜索了這個問題,但沒有答案爲我工作。每次我調試我的應用程序時,都會給我這個錯誤。執行時出現意外錯誤
Unexpected error while executing: am start -n "com.example.maomei.passusersystem/com.example.maomei.passusersystem.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Error while Launching activity
這裏是我的MainActivity代碼:
public class MainActivity extends AppCompatActivity {
TextView textView1;
Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView1 = (TextView) findViewById(R.id.textView1);
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button1:
Intent myIntent = new Intent(MainActivity.this, Main2Activity.class);
MainActivity.this.startActivity(myIntent);
}
}
});
}
}
和我的清單代碼:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maomei.passusersystem">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="com.example.maomei.passusersystem.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Main2Activity"
android:label="@string/title_activity_main2"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Main4Activity"
android:label="@string/title_activity_main4"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Main5Activity"
android:label="@string/title_activity_main5"
android:theme="@style/AppTheme.NoActionBar">
</activity>
</application>
</manifest>
爲什麼使用爲Button1開關,當你在Button1的onClickLinstener? – Koorosh