[英]Android ActivityNotFoundException
我正在嘗試創建一個非常簡單的自定義意圖示例。 我搜索過這個錯誤,沒有一個論壇有適合我的答案。 這是我的文件:
public class DemoImplicit extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void whenButtonIsClicked(View view) {
Intent intent = new Intent("com.example.action.NEW_ACTION"); //<<<<<<<
intent.addCategory("android.intent.category.DEFAULT"); //<<<<<<<
// Intent intent = new Intent("android.intent.action.VIEW");
// intent.addCategory("com.example.MY_CATEGORY");
startActivity(intent); //<<<<<<<
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demos" android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".SatisfyIntent" android:label="@string/app_name">
<intent-filter>
<!-- action android:name="android.intent.action.VIEW" / -->
<!-- category android:name="com.example.MY_CATEGORY" / -->
<action android:name="com.example.action.NEW_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
這兩個單獨的文件位於兩個不同的Eclipse項目中,但我確保在將包含startActivity調用的文件加載到模擬器之前,將包含intent-filter的項目加載到模擬器上。 無論如何,我總是得到一個ActivityNotFoundException。 我究竟做錯了什么?
PS這是包含DemoImplicit.java的項目的AndroidManifest.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demos"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".DemoImplicit"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
您應該確保您的AndroidManifest.xml
文件必須在DemoImplicit
定義DemoImplicit
Activity。
就像這樣: <activity android:name=".DemoImplicit"/>
同樣在您的代碼中,您已將SatisfyIntent
為啟動器活動
<activity android:name=".SatisfyIntent" android:label="@string/app_name">
但是在這里,您似乎在Java代碼中沒有這樣的東西。
因此,底線是:您要運行的Activity
必須已在AndroidManifest.xml
文件中定義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.