【问题标题】:How to define several activities from different packages inside the manifest file?如何在清单文件中定义来自不同包的多个活动?
【发布时间】:2011-07-16 14:51:11
【问题描述】:

我这几天遇到这个问题。我的项目中有两个包。从我的家(在家庭包内)活动中,我将使用按钮 onClickListener 方法调用我的个人资料活动(在个人资料包内)。这是代码

 private OnClickListener bProfileListener = new OnClickListener() {
    public void onClick(View v) {

        Toast.makeText(getApplicationContext(),
                " You are heading to your Profile page", Toast.LENGTH_SHORT).show();

        Intent intent = new Intent(v.getContext(), Profile.class);          
        startActivityForResult(intent, 0);

    }

}; }

这是我的清单文件。首先,我像这样定义包名称 package="com.and.profile"。

<application android:label="@string/app_name"
             android:icon="@drawable/icon">
    <activity android:name=".home.Home"
              android:launchMode="singleTask"
              android:stateNotNeeded="true"
              android:label="@string/app_name"
              android:theme="@android:style/Theme.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.HOME"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>        
    <activity android:name=".profile.Profile"
    android:label="@string/app_profile"
    android:icon="@drawable/icon"
    android:theme="@android:style/Theme.NoTitleBar">
    </activity>
    <activity android:name=".profile.CustomListViewDB"
    android:label="@string/app_profile"
    android:icon="@drawable/icon">
    </activity>
</application>

当我运行这个方法时,我得到了这个主要错误...... 错误/AndroidRuntime(791): android.content.ActivityNotFoundException: 找不到明确的活动类 {com.and.profile.Profile};您是否在 AndroidManifest.xml 中声明了此活动?

谁能告诉我该怎么做。我错过了什么吗?非常感谢。

【问题讨论】:

标签: android android-activity android-manifest


【解决方案1】:

尝试将所有类替换为其完全限定名。

即:将.profile.Profile 更改为com.and.profile.Profile

这应该解决它!之后,检查类名和其他字段中的拼写错误!

【讨论】:

    【解决方案2】:

    您是否已将 profile.Profile 包(或您正在使用的任何其他包)导入到您尝试从中调用它们的文件中?

    【讨论】:

    • public static final 类布局 { public static final int home_application_item=0x7f030000;公共静态最终 int home_main=0x7f030001;公共静态最终 int profile_main=0x7f030002;公共静态最终 int 简单=0x7f030003;公共静态最终 int single_item=0x7f030004;我不知道为什么它仍然缺少活动。你有什么线索吗?我必须对清单文件进行一些更改吗?
    • 不太明白,为什么要明确声明/导入 R.class?没有必要这样做。
    • 我已经尝试过在每个类的开头不导入 .R 类,但是我的所有对象都变成了错误,因为错误出现在每个 findViewById(R.id.something) 中的 R 字母下方.
    • 我指的是 Android 生成的 R.java 文件。你有不止一个吗?即便如此,我认为您不需要显式导入这些。
    猜你喜欢
    • 1970-01-01
    • 2016-08-31
    • 1970-01-01
    • 2012-03-12
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    相关资源
    最近更新 更多