尝试启动第二个活动时的ActivityNotFoundException

时间:2014-08-16 19:12:18

标签: java android android-intent activitynotfoundexception

我刚刚开始学习Android应用程序编程,我正在关注Android官方基础知识教程,但我不明白为什么我在制作故意时出错了应用程序会抛出这个错误。

public class MainActivity extends ActionBarActivity {

    public static final String EXTRA_MESSAGE = "com.panagetstudios.androidapp.MESSAGE";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void sendMessage(View view){
        Intent inte = new Intent(this, DisplayMessageActivity.class);
        EditText edittext = (EditText) findViewById(R.id.edit_message);
        String text = edittext.getText().toString();
        inte.putExtra(EXTRA_MESSAGE, text);
        startActivity(inte);
    }

}

这是我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.panagetstudios.androidapp"
    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=".DisplayMessageActivity"
        android:label="@string/title_activity_display_message" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.panagetstudios.androidapp.MainActivity" />
        </activity>

    </application>

</manifest>

请帮助我,我迷失了,如有必要,我可以为您提供更多信息。

此致

3 个答案:

答案 0 :(得分:0)

您应该拥有活动的完整包名称:

<activity
    android:name="com.panagetstudios.androidapp.DisplayMessageActivity"
    android:label="@string/title_activity_display_message" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.panagetstudios.androidapp.MainActivity" />
    </activity>

另外,请确保您的活动位于文件夹src / com.panagetstudios.androidapp

答案 1 :(得分:0)

试试这个

<activity
    android:name=".DisplayMessageActivity"
    android:label="@string/title_activity_display_message" >
    <intent-filter>
            <action android:name="android.intent.action.DISPLAY" />

            <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

答案 2 :(得分:0)

没关系,我刚刚找到了解决方案。我只是以管理员身份执行Eclipse并重启我的项目并且它正常工作,谢谢你的合作