[英]No Activity found to handle Intent
我知道有很多與這個問題相關的問題,但沒有一個能解決我的問題。 我制作了一個包含 50 個問題片段的測驗應用程序。 在最后一個問題(問題 50 片段)中,我調用了分數 Activity 來顯示分數。 在這個 Activity 中,我創建了一個“Play Again”按鈕,它再次調用 Main Activity 來開始游戲。 但是每次我點擊“再次播放”按鈕時,我的應用程序都會崩潰。
Logcat 錯誤: 04-03 15:34:43.638 26316-26316/com.example.moresche.englishqigame E/AndroidRuntime: FATAL EXCEPTION: main android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.moresche.englishqigame.MainActivity }
評分活動.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_score);
Typeface mTypeface = Typeface.createFromAsset(getAssets(),"chlo.TTF");
TextView myTextview = (TextView)findViewById(R.id.txtla);
myTextview.setTypeface(mTypeface);
Typeface m2Typeface = Typeface.createFromAsset(getAssets(),"chlo.TTF");
TextView m2yTextview = (TextView)findViewById(R.id.txtla1);
m2yTextview.setTypeface(m2Typeface);
initControls();
}
public void initControls() {
TextView final_score = (TextView) findViewById(R.id.textView103);
TextView final_scoreqi = (TextView) findViewById(R.id.textView104);
TextView lvlqi = (TextView) findViewById(R.id.textViewzzz);
Button btnxd = (Button)findViewById(R.id.btnx);
final SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
...
btnxd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
app_preferences.edit().clear().commit();
Intent intent1 = new Intent ("com.example.moresche.englishqigame.MainActivity");
startActivity(intent1);
}
});
清單文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.moresche.englishqigame">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".scoreActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.example.moresche.englishqigame.scoreActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
你以錯誤的方式調用你的意圖。
Intent intent1 = new Intent ("com.example.moresche.englishqigame.MainActivity");
它應該是這樣的:
Intent intent1 = new Intent(scoreActivity.this,MainActivity.class);
http://developer.android.com/training/basics/firstapp/starting-activity.html
雖然那只會帶你到頁面而不是再次玩游戲。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.