[英]Android ActivityNotFoundException
I'm trying to create a very simple custom intent example. 我正在尝试创建一个非常简单的自定义意图示例。 I've searched for this error and none of the forums have answers that work for me.
我搜索过这个错误,没有一个论坛有适合我的答案。 Here are my files:
这是我的文件:
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>
These two separate files are in two different Eclipse projects, but I make sure to load the project containing the intent-filter onto the emulator before loading the file containing the startActivity call onto the emulator. 这两个单独的文件位于两个不同的Eclipse项目中,但我确保在将包含startActivity调用的文件加载到模拟器之前,将包含intent-filter的项目加载到模拟器上。 In any case, I always get an ActivityNotFoundException.
无论如何,我总是得到一个ActivityNotFoundException。 What am I doing wrong?
我究竟做错了什么?
PS Here's the AndroidManifest.xml file for the project containing DemoImplicit.java: 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>
Fisrtly you shuld ensure that your AndroidManifest.xml
file must have defined the DemoImplicit
Activity in this. 您应该确保您的
AndroidManifest.xml
文件必须在DemoImplicit
定义DemoImplicit
Activity。
As like this: <activity android:name=".DemoImplicit"/>
就像这样:
<activity android:name=".DemoImplicit"/>
Also in your code you have aspecified the SatisfyIntent
as a launcher Activity 同样在您的代码中,您已将
SatisfyIntent
为启动器活动
<activity android:name=".SatisfyIntent" android:label="@string/app_name">
But here it seems like you have nothing like this in your Java Code. 但是在这里,您似乎在Java代码中没有这样的东西。
So the Bottom line is that: Activity
which you want to run must have defined in your AndroidManifest.xml
file. 因此,底线是:您要运行的
Activity
必须已在AndroidManifest.xml
文件中定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.