【问题标题】:Weird ActivityNotFoundException for class in a library project库项目中类的奇怪 ActivityNotFoundException
【发布时间】:2013-10-25 11:23:05
【问题描述】:

我收到了一个 ActivityNotFoundException 的活动,该活动存在并包含在我的应用程序 AndroidManifest.xml 中。

这是我的场景:

我的应用项目包是:com.myapplynx.mytexteditor.android

我的库项目包是com.myapplynx.mytexteditor.common

我的库项目已正确包含在我的应用程序项目中,因为我可以在我的应用程序项目中使用库项目中的其他类。

活动MyTedAdvancedPreference 位于我的库项目com.myapplynx.mytexteditor.common.prefs 包下。

在我的应用程序项目中,我有一个 xml,res/xml/prefs.xml,我在其中定义了首选项,包括调用 MyTedAdvancedPreference 的首选项屏幕,如下所示:

    <PreferenceScreen android:title="@string/config_cat_advanced" >
        <intent android:action="android.intent.action.VIEW"
            android:targetPackage="com.myapplynx.mytexteditor.android"
            android:targetClass="com.myapplynx.mytexteditor.common.prefs.MyTedAdvancedPreferences"/> 

请注意,MyTedAdvancedPreferences 包含在我的应用程序项目 AndroidManifest.xml 中:

  <application
   .....
   <activity android:name="com.myapplynx.mytexteditor.common.prefs.MyTedAdvancedPreference"
       android:label="@string/title_settings"
         android:theme="@style/MyApplynxTheme" >       
    </activity>
   ....
   </application>

我的应用程序编译并运行正常。因此,当我访问我的设置页面并尝试访问MyTedAdvancedPreference 时,我得到一个ActivityNotFoundException

10-25 14:15:52.734: E/AndroidRuntime(19049): FATAL EXCEPTION: main
10-25 14:15:52.734: E/AndroidRuntime(19049): android.content.ActivityNotFoundException:   Unable to find explicit activity class {com.myapplynx.mytexteditor.android/com.myapplynx.mytexteditor.common.prefs.MyTedAdvancedPreferences}; have you declared this activity in your AndroidManifest.xml?

活动在我的应用程序中定义(com.myapplynx.mytexteditor.androidAndroidManifest.xml。我究竟做错了什么?谢谢。

【问题讨论】:

  • 请发布您的整个清单文件。
  • 检查构建路径 -> 订购/导出 - 确保私人图书馆被标记为导出
  • 嗨,Tomislav,已经完成了。谢谢。

标签: java android xml eclipse android-activity


【解决方案1】:

看起来类似于另一个问题ActivityNotFoundException when different package's targetClass in PreferenceScreen

这是描述解决方法的答案,表明这是框架中的错误:

他的建议是从“损坏的”Activity 继承,将继承的代码放在您的主应用项目中。然后在您的主清单中正常引用它。

【讨论】:

  • 我从不认为这是一个错误,感谢您指出。希望它得到修复。感谢您的回答。谢谢。
  • 您可以点击答案左侧的“勾选”图标,就在“投票”数字的下方。谢谢
【解决方案2】:

尝试添加 Intent-Filter 并给出

操作(com.myapplynx.mytexteditor.common.prefs)。

  <application
       .....
       <activity android:name="com.myapplynx.mytexteditor.common.prefs.MyTedAdvancedPreference"
           android:label="@string/title_settings"
             android:theme="@style/MyApplynxTheme" >
        <intent-filter>
                <action android:name="com.myapplynx.mytexteditor.common.prefs" />

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

并尝试调用 Activity 之类的

Intent intent=new Intent("com.myapplynx.mytexteditor.common.prefs");//action
intent.startActivity(intent);

希望它应该工作。

【讨论】:

  • 不完全是我想要实现的目标,因为我需要从 prefs.xml 调用活动。除非你举个例子。不过还是谢谢。
【解决方案3】:

在您的清单中更改:

   <activity android:name="com.myapplynx.mytexteditor.common.prefs.MyTedAdvancedPreference"
   android:label="@string/title_settings"
     android:theme="@style/MyApplynxTheme" >       
</activity>

到这里:

   <activity
            android:name="MyTedAdvancedPreference"
            android:label="@string/title_settings"
            android:theme="@style/MyApplynxTheme" >
            <intent-filter>
                <action android:name="example.action.ACTION_PREF_ACTIVITY" />

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

您的 pref.screen 应该如下所示:

    <PreferenceScreen android:title="@string/config_cat_advanced" >
        <intent android:action="example.action.ACTION_PREF_ACTIVITY" >
        </intent>
    </PreferenceScreen>

【讨论】:

  • @nmvictor 我更新了答案,action android:name 应该等于您在 pref.screen 中定义的操作。如果您需要任何帮助,请告诉我。
猜你喜欢
  • 1970-01-01
  • 2015-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多