繁体   English   中英

Android:使用Intent启动新活动时找不到活动

[英]Android: Activity not found when starting new activity using intent

我正在尝试从现有活动中启动新活动,但是我发现活动未找到异常。

这是我的代码和logcat错误的精简版本。 任何帮助将非常感激。

主要活动

public class MainActivity extends FragmentActivity {

/* (non-Javadoc)
 * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);        
    startActivity(new Intent(this, TermsAndConditions.class));
}
....

}

新活动

public class TermsAndConditions extends Activity{

    /* (non-Javadoc)
     * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.terms_and_conditions);

    }
}

Android清单

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

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="17" />


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" 
        android:screenOrientation="sensorLandscape">
        <activity
            android:name=".MainActivity"
            android:screenOrientation="landscape" 
            android:configChanges="keyboardHidden|orientation"
            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:label="@string/app_name" android:name=".TermsAndConditions"></activity>


    </application>
</manifest>

Logcat

04-02 16:48:43.255: E/AndroidRuntime(20856): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.app/com.example.app.TermsAndConditions}; have you declared this activity in your AndroidManifest.xml?
<activity android:label="@string/app_name" android:name="com.example.app.TermsAndConditions"></activity>

clean您的项目,

希望这对您有所帮助。

问题是,您已经告诉Main Activity发送了意图,但没有告诉条款和条件活动来接收意图。 为此,请在Ts和Cs页面的onCreate方法中在setContentView之后进入getIntent()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM