1

我已经在 Android Manifest 中声明了我的所有类,但由于某种原因,我不断收到 ActivityNotFoundException。

AndroidManifest.xml

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

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

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

    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />

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

    <application
        android:name=".activities.CalorieApplication"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".activities.AActivity"
            android:label="@string/title_activity_a"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name=".activities.BActivity"
            android:label="@string/title_activity_b"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name=".activities.CActivity"
            android:label="@string/title_activity_c"
            android:screenOrientation="portrait" >
        </activity>

        <activtity
            android:name=".activities.DActivity"
            android:label="@string/title_activity_d"
            android:screenOrientation="portrait" />


        <activity
            android:name=".activities.EActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

这是给我带来麻烦的电话

Intent intent = new Intent ( AActivity.this, BActivity.class );
                startActivity ( intent );

BActivity.java

package com.wks.calorieapp.activities;



public class BActivity extends Activity
{
    private static final String TAG = BActivity.class.getCanonicalName ();

    private EditText editSearch;
    private Button buttonSearch;
    private ViewSwitcher viewSwitcher;
    private RelativeLayout viewLoading;
    private LinearLayout viewResults;
    private TextView textLoading;
    private ProgressBar progressLoading;
    private ExpandableListView listNutritionInfo;

    private enum BActivityView{VIEW_IDLE,VIEW_LOADING,VIEW_RESULTS};
    private BActivityView searchActivityView;

    @Override
    protected void onCreate ( Bundle savedInstanceState )
    {
        super.onCreate ( savedInstanceState );
        this.setContentView ( R.layout.activity_b );
        setupView();
        setupListeners();
    }

完整的堆栈跟踪:

06-22 21:01:50.625: E/AndroidRuntime(18120): FATAL EXCEPTION: main
06-22 21:01:50.625: E/AndroidRuntime(18120): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.wks.calorieapp/com.wks.calorieapp.activities.BActivity}; have you declared this activity in your AndroidManifest.xml?
06-22 21:01:50.625: E/AndroidRuntime(18120):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1511)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1387)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at android.app.Activity.startActivityForResult(Activity.java:3195)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at android.app.Activity.startActivity(Activity.java:3302)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at com.wks.calorieapp.activities.HomeActivity$OnGridActivitiesClicked.onItemClick(EActivity.java:89)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at android.widget.AdapterView.performItemClick(AdapterView.java:292)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at android.widget.AbsListView.performItemClick(AbsListView.java:1181)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2709)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at android.widget.AbsListView$1.run(AbsListView.java:3464)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at android.os.Handler.handleCallback(Handler.java:605)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at android.os.Handler.dispatchMessage(Handler.java:92)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at android.os.Looper.loop(Looper.java:137)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at android.app.ActivityThread.main(ActivityThread.java:4511)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at java.lang.reflect.Method.invokeNative(Native Method)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at java.lang.reflect.Method.invoke(Method.java:511)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
06-22 21:01:50.625: E/AndroidRuntime(18120):    at dalvik.system.NativeStart.main(Native Method)
4

5 回答 5

1

你的清单有问题。请根据代码检查您的主包

包="com.abc.calorieapp"
所以你所有的子包(规范包)都会像这样
com.abc.calorieapp.activities.AActivity

现在真正的问题是你最初使用包作为包 com.wks.calorieapp.activities

这就是为什么您的应用无法获得真实活动的原因。

请将清单中的包更改为package="com.wks.calorieapp"

并且您的应用程序应该可以正常工作。

于 2013-06-22T18:22:24.687 回答
1

一切看起来都很好,从你描述的情况来看,你已经把一切都设置好了。

当其他一切都失败时,请始终确保

  1. Eclipse 是最新的
  2. ADT 插件是最新的,并且
  3. 安装了 SDK 管理器中的最新工具

然后再试一次。

有时,构建和部署过程似乎只是以某种方式搞砸了。

这似乎对这个人有所帮助:https ://stackoverflow.com/a/9552169/833647 (以及有关 StackOverflow 的各种其他问题/答案)

于 2013-06-22T18:52:57.327 回答
1

对于除了启动器之外的所有活动,请确保它们也具有与启动器一样的意图过滤器,但如下所示。

<intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

而不是 LAUNCHER 放 DEFAULT,试试看

于 2013-06-22T21:46:28.073 回答
-1

只在你的清单文件中写 android:name=".BActivity" 希望它能工作,祝你好运

于 2013-06-22T17:03:02.057 回答
-1

我从来没有把包名放在活动名前面。因此,删除清单中 Activity 名称前面的 .activities ,然后它应该可以工作了..

于 2013-06-22T17:03:54.110 回答