W.K.S
W.K.S

Reputation: 10095

Android can't find class even though it's declared in manifest

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)

Upvotes: 1

Views: 11554

Answers (5)

Asiimwe
Asiimwe

Reputation: 2259

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

Upvotes: 1

Ken Wolf
Ken Wolf

Reputation: 23269

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)

Upvotes: 1

Ajay Kumar Meher
Ajay Kumar Meher

Reputation: 1952

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.

Upvotes: 1

harmjanr
harmjanr

Reputation: 937

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..

Upvotes: -1

Rauf
Rauf

Reputation: 46

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

Upvotes: -1

Related Questions