安卓:ActivityNotFoundException

标签 android classnotfound

我是 android 和 java 编程的新手,我在我的应用程序中收到 ActivityNotFoundException。

这里是 Activity 被调用的仅有的两次:

public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // TODO Auto-generated method stub
            String selectedItem = (String) lvCheckLists.getItemAtPosition(position);

            Intent i= new Intent("com.teamvdb.checklist.checkListActivity");
            // Package name and activity
            // Intent i= new Intent(MainActivity.this,SecondActivity.Class);
            // Explicit intents
            i.putExtra("selectedItem",selectedItem);
            // Parameter 1 is the key
            // Parameter 2 is your value
             startActivity(i);

             Intent openCheckListActivity = new ntent("com.teamvdb.checklist.checkListActivity");
             startActivity(openCheckListActivity);

        }
    }); 
}

这是我的 Android list :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.teamvdb.checklist"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="21" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity android:name=".MainActivity"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />

    </intent-filter>
</activity>
    <activity android:name=".checkListActivity"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.MAIN" />

    </intent-filter>
</activity>
</application>
</manifest>

我花了最后 20 分钟试图弄清楚它出了什么问题,但我看不到问题所在。 是的,类(class)拼写正确。

最佳答案

显式启动 checkListActivity :

public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
    String selectedItem = (String) lvCheckLists.getItemAtPosition(position);
    Intent i= new Intent(MainActivity.this,checkListActivity.class);
    i.putExtra("selectedItem",selectedItem);
    startActivity(i);
});

checkListActivity 不需要 intent-filter,所以删除它并在 AndroidManifest.xml 中定义为简单:

<activity android:name=".checkListActivity"/>

注意:删除不必要的再次启动checkListActivity的代码。

关于安卓:ActivityNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27457473/

相关文章:

java - 为什么我不能生成签名的 APK?

java - Android BLE发送数据

javascript - Google map API 不适用于 PhoneGap - 生成空白页

php - 使用命名空间 (PHP) 的 TDD - 找不到类

java - 数据库在导出的 apk 中不起作用?

android - 运行 OpenCV 混合处理教程时出现 UnsatisfiedLinkError

java.lang.NoClassDefFoundError : org/apache/poi/ss/usermodel/Row Error during runtime

php - 扩展时找不到类

java - ClassNotFoundException 安卓

c# - Xamarin 自定义 View ClassNotFoundException