1

I've declared all my classes in the Android Manifest but for some reason I keep getting an 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>

and here's the call that's giving me trouble

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();
    }

Full Stacktrace:

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)
W.K.S
  • 9,787
  • 15
  • 75
  • 122
  • 2
    Please paste the entire stack trace, and please confirm that `BActivity.class` really resides in `com.abc.calorieapp.activities`. – CommonsWare Jun 22 '13 at 17:02
  • Yes, the class is definitely in the package. – W.K.S Jun 22 '13 at 17:07
  • Try fully-qualifying the class name in the `android:name` attribute in the manifest (i.e., use `com.wks.calorieapp.activities.BActivity` instead of `.activities.BActivity`). – CommonsWare Jun 22 '13 at 17:10
  • I tried that, it didn't work – W.K.S Jun 22 '13 at 17:11
  • post your code where you start activity `BActivity` using intent. – Raghunandan Jun 22 '13 at 17:13
  • 1
    does your BActivity extend any class other than the standard Activity? (ie maybe you are using the support library) – Plato Jun 22 '13 at 17:33
  • Nope, it extends Activity – W.K.S Jun 22 '13 at 17:36
  • 1
    When everything else fails... make sure Eclipse is up to date, and the ADT plugin is up to date, and the latest tools are installed..and try again. Seemed to help this guy: http://stackoverflow.com/a/9552169/833647 – Ken Wolf Jun 22 '13 at 17:44
  • As Plato sort of suggested, a strong dependence on something else which is missing (such as a library, or perhaps your BActivityView class) can cause an Activity to go missing at runtime. It's possible that a relevant error message would be logged during the install/dex optimizing process in some of these cases. – Chris Stratton Jun 22 '13 at 18:15
  • @KenWolf That worked! Could you please write that as the answer? – W.K.S Jun 22 '13 at 18:46
  • 1
    @W.K.S well, since you insist :) Done. Thanks, good sportsmanship! – Ken Wolf Jun 22 '13 at 18:53

5 Answers5

1

It's a problem with your manifest. Please check your main package as per the code

package="com.abc.calorieapp"
so all you sub-packages(canonical package) will follow this like
com.abc.calorieapp.activities.AActivity

Now the real issue is you have used package originally as package com.wks.calorieapp.activities

This is why your app is not able to get the real activity.

Please change the package in your manifest as package="com.wks.calorieapp"

and your app should work fine.

Ajay Kumar Meher
  • 1,932
  • 16
  • 24
1

Everything looks OK and from what you describe you've set everything up fine.

When everything else fails, always make sure

  1. Eclipse is up to date
  2. The ADT plugin is up to date, and
  3. The latest tools from the SDK manager are installed

and try again.

Sometimes the build and deploy process just seems to get screwed up somehow.

It seemed to help this guy: https://stackoverflow.com/a/9552169/833647 (and various other questions/answers around StackOverflow)

Community
  • 1
  • 1
Ken Wolf
  • 23,133
  • 6
  • 63
  • 84
1

For all your activities apart from the launcher one make sure they also have an intent-filter just as the launcher but as follows.

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

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

Instead of LAUNCHER put DEFAULT, try and see

Asiimwe
  • 2,199
  • 5
  • 24
  • 36
-1

Only write android:name=".BActivity" in Your manifest file Hope it will work ,Best Of Luck

Rauf
  • 46
  • 8
-1

I never put the package name in front of the Activity name. So remove the .activities in front of the Activity name in your Manifest, it should work then..

harmjanr
  • 930
  • 2
  • 11
  • 27
  • in the manifest tag, the package declaration says `com.abc.calorieapp`, but my classes are in another subpackage called `.activities` so I need to add that tag to give the full package specification of the class. – W.K.S Jun 22 '13 at 17:09