ActivityNotFound exception-声明Activity

时间:2014-01-17 03:37:38

标签: android

我拥有它,以便当用户点击列表视图中的项目时,它们将被带到显示该项目的另一个活动。但是,当我测试它时,它会抛出一个ActivityNotFound异常,即使我已经在清单中明确定义了它。任何其他类都不会发生这种情况。有关如何修复的任何想法?以下是导致错误的代码行,特别是ctx.StartActivity ...

listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id ){
            xMessage = (String) parent.getItemAtPosition(position);
            y = true;
            setView(xMessage,R.layout.messageclicked, R.id.mS);

            ctx.startActivity(new Intent(getActivity(),showMessage.class));

        }

    });

这里是Manifest部分,我宣布了这个类:

<activity android:name = "com......showMessage" />

......是隐藏敏感信息的。基本上它是com.x.y.showRide,这是此Activity的正确文件路径。这是清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="......."
    android:versionCode="1"
    android:versionName="1.0" >

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

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.......SplashScreen"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/app_name"
            android:noHistory="true"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.........MainMenu"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar" />
        <activity
            android:name="com........Register"
            android:configChanges="orientation|keyboardHidden"
            android:parentActivityName=".MainMenu"
            android:screenOrientation="portrait"
            android:theme="@style/.....Theme" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainMenu" />
        </activity>
        <activity
            android:name="com......SignIn"
            android:configChanges="orientation|keyboardHidden"
            android:parentActivityName=".MainMenu"
            android:screenOrientation="portrait"
            android:theme="@style/......Theme" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainMenu" />
        </activity>
        <activity android:name="com......MainNavigation" />
        <activity android:name="com........MainScreen" />
        <activity android:name="com.......MainActivity" />
        <activity
            android:name="com.RuMad.......FindARide"
            android:label="@string/title_activity_find_aride" >
        </activity>
        <activity android:name=".OfferRide"/>
        <activity android:name=".RequestRide"/>
        <activity android:name ="com......Compose"/>
        <activity android:name ="com.......IntendedUses"/>
        <activity android:name ="com.......showPreference"/>  
        <activity android:name = "com.......myRides"/>  
        <activity android:name = "com.......showMessage"/>
        <activity android:name ="com......OffRe"/>
        <activity android:name = "com......showRide" />    
        </application>

</manifest>

2 个答案:

答案 0 :(得分:1)

解决此问题的一种方法可能是:

在托管此片段的Activity中,创建一些函数,比如说

public void startShowMessageActivity(){
       Intent intent = new Intent(this, showMessage.class);
       startActivity(intent);
}

在你的片段类中,使用Activity的上下文调用此方法 - 我认为是ctx(在你的代码中)

因此,基本上,请说活动是MainActivity.java

(MainActivity(ctx)).startShowMessageActivity();

如果上述说法不起作用,请尝试

MainActivity obj = (MainActivity)getActivity();
obj.startShowMessageActivity();

希望这有帮助!

答案 1 :(得分:0)

假设您当前的活动是MainActivity,请使用此行

startActivity(new Intent(MainActivity .this,showMessage.class))