我想創建一個非常簡單的自定義意圖示例。我搜索了這個錯誤,沒有任何論壇的答案適合我。下面是我的文件: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調用文件加載到仿真器之前加載包含意圖過濾器在仿真器上的項目。無論如何,我總是得到一個ActivityNotFoundException。 我在做什麼錯?
P.S.下面是含有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文件。我編輯的問題包括兩個。一個列出了一個啓動器的活動;另一個沒有。所以我不認爲這是問題。它可能是標識符和它的值之間的區別,比如com.example.demos.MY_ACTIVITY與值MY_NEW_ACTIVITY? – hwexler2 2011-02-06 16:46:12