ActivityNotFoundException(是的,此活动在 AndroidManifest.xml 中声明)

发布于 2024-11-15 07:37:23 字数 1094 浏览 3 评论 0原文

我发现一些线程报告了类似的问题,但没有一个< /a> 确实提供了一些我还没有尝试过的东西。

一个无辜的这样的调用:

mActivity.startActivity(new Intent(mActivity, MyEditPreferences.class));

在 AndroidManifest.xml 中使用以下内容:

 <application>
    <activity android:name="MyActivityLib" />
    <activity android:name="com.example.baseapp.MyEditPreferences" android:label="@string/app_name">
    </activity>
 </application>

触发以下异常:

06-14 14:06:50.297: ERROR/AndroidRuntime(9272): 
android.content.ActivityNotFoundException: Unable to find explicit activity class
{com.example.baseapp.paypal/com.example.baseapp.MyEditPreferences};
have you declared this activity in your AndroidManifest.xml?

事实是,在我将其从单一应用程序项目更改为由库项目组成的由两部分组成的项目之前,此代码曾经完美地工作和一个应用程序项目。

AndroidManifest.xml 是library 项目中的一个。

我需要做什么来消除这个 ActivityNotFoundException

I found a few threads reporting a similar problem but none of them really offers something that I haven't tried already.

An innocent such call:

mActivity.startActivity(new Intent(mActivity, MyEditPreferences.class));

with the following in AndroidManifest.xml:

 <application>
    <activity android:name="MyActivityLib" />
    <activity android:name="com.example.baseapp.MyEditPreferences" android:label="@string/app_name">
    </activity>
 </application>

Triggers the following exception:

06-14 14:06:50.297: ERROR/AndroidRuntime(9272): 
android.content.ActivityNotFoundException: Unable to find explicit activity class
{com.example.baseapp.paypal/com.example.baseapp.MyEditPreferences};
have you declared this activity in your AndroidManifest.xml?

The things is, this code used to work flawlessly before I changed it from a monolithic application project to a 2-part project that is comprised from a Library Project and an Application Project.

The AndroidManifest.xml is the one in the library project.

What do I need to do eliminate this ActivityNotFoundException?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

剪不断理还乱 2024-11-22 07:37:23

我刚刚解决了这个问题。

我所要做的就是将 FQN 添加到 Application 项目的 AndroidManifest.xml 中:

<activity android:name="com.example.baseapp.MyEditPreferences"
          android:label="com.example.baseapp.MyActivityLib:string/app_name">
</activity>

事实上,我删除了 MyEditPreferences 中的任何引用。 strong>Library 项目的 AndroidManifest.xml 完全正确,并且仍然有效。

它也适用于原始的 startActivity 1 行语句:

mActivity.startActivity(new Intent(mActivity, MyEditPreferences.class));

结论:重要的是应用程序的 AndroidManifest.xml,而不是库的。

I just solved the problem.

All I had to do was add the FQN to the Application project's AndroidManifest.xml:

<activity android:name="com.example.baseapp.MyEditPreferences"
          android:label="com.example.baseapp.MyActivityLib:string/app_name">
</activity>

In fact, I removed any reference to MyEditPreferences in the Library project's AndroidManifest.xml completely and it still works.

It also works with the original startActivity 1-line statement:

mActivity.startActivity(new Intent(mActivity, MyEditPreferences.class));

Conclusion: It's the application's AndroidManifest.xml that matters, not the library's.

维持三分热 2024-11-22 07:37:23

也许这会起作用?

Intent mIntent = new Intent();
mIntent.setClassName(mActivity, "com.example.baseapp.MyEditPreferences");
mActivity.startActivity(mIntent);

Maybe this will work?

Intent mIntent = new Intent();
mIntent.setClassName(mActivity, "com.example.baseapp.MyEditPreferences");
mActivity.startActivity(mIntent);
梦幻的味道 2024-11-22 07:37:23

如果您使用的类名称包含在 android 包中(设置、首选项、活动等),则需要添加以下内容:

Intent i = new Intent(this, <name_of_your_package>.classname.class);

如果您不添加“name_of_your_package”,编译器会认为您正在引用android 包中的类 (android.*)。

If you use classes which names are included in an android package (Settings, Preferences, Activity, ...), you will need to put this:

Intent i = new Intent(this, <name_of_your_package>.classname.class);

If you don't put "name_of_your_package", the compiler will think that you are refering to the class in android package (android.*).

秋日私语 2024-11-22 07:37:23

我知道这是一个非常古老的线程,但我也遇到了同样的问题。就我而言,我所要做的就是删除一个虚假的

import java.util.prefs.Preferences;

I know this is a very old thread, but I've just had the same problem. In my case all I had to do was to delete a spurious

import java.util.prefs.Preferences;
无妨# 2024-11-22 07:37:23

只需检查清单中是否有 IDE 未指出的错误即可。

Just check your manifest for errors that your IDE not pointed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文