android.content.ActivityNotFoundException: Unable to find explicit activity class
Asked Answered
C

9

29

I get this error:

06-06 10:45:19.685: E/AndroidRuntime(554): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.Android.myApp/com.Android.myApp.Facebook.Example}; have you declared this activity in your AndroidManifest.xml?

But i have declared it in my manifest file. what might be the other reasons for such exception?

My manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.Android.myApp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="4" />

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Light" >

        <activity
            android:name=".SignUpActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".SignInActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".HomeActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".selectCityActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".FeedListViewActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".SearchActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".IWantActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".DateActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".ShareActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".ShareProductActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".SharePriceActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".ShareStoreActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".ProfileActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".ShowMapActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".ParticularEntryActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".MyLocationActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".MapMarkerActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".BarcodeActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".BarcodeResult"
            android:label="@string/app_name" />
        <activity
            android:name=".FeedbackActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".SplashActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".Example"
            android:label="@string/app_name" />

        <uses-library android:name="com.google.android.maps" />
    </application>

</manifest>
Croce answered 6/6, 2012 at 5:18 Comment(9)
Maybe the library class is not referred properlyPopinjay
how to make sure it is referred properly??...its there in the properties --> Library.Croce
show your Manifest file.Sylvanus
@Lalit Poptani...this is what i included in my manifest.xml...<activity android:name=".Example" android:label="@string/app_name" />Croce
@Archie.bpgc complete Manifest file with do to understand not a single line.Sylvanus
From your exception which one is your class - Facebook or Example Because, you declared in package in manifest as com.android.myapp but for facebook activity you declared com.android.myapp.Facebook.ExampleNeckpiece
Example is my activity in com.Android.myApp.Facebook packageCroce
If example is your activity means, you should declared your activity as com.android.myapp.Facebook.Example Because, its from different package or your Activity name as Facebook.Example. Am i right?Neckpiece
yeah...i never used this way...it workedCroce
F
42

You declared package name in the manifest as com.Android.myApp and Activity Name .Example.So android will search it from com.Android.myApp.Example. But your activity is residing in "com.Android.myApp/com.Android.myApp.Facebook.Example".So give the activity name as .Facebook.Example or full path as given below In the manifest

<activity
                android:name="com.Android.myApp.Facebook.Example">

</activity>
Fussy answered 6/6, 2012 at 5:23 Comment(2)
Tag <activity> attribute name has invalid character '/'.Croce
The key point is to remember to include the dot "." at the front, when declaring the Activity without the full package name. It's easy to forget this dot, and Android Studio will sometimes suggest (auto-complete) without the dot! When the dot is missing, you will get this error unexpectedly.Hydrant
N
6

you can also use

<activity
        android:name=".Facebook.Example"
        android:label="@string/app_name" />
Nolan answered 6/6, 2012 at 7:1 Comment(0)
C
6

I got a variation to this problem. I was launching an activity called "Settings" and getting the same error and making all the suggested changes to the manifest were not fixing the problem.

Thing is, in the calling activity, I was also using / importing android.provider.Settings, so from what I can see when trying to launch the activity it was getting confused between the two. Thus I changed this in the code rather than the manifest to include the full path:

Intent launchScr = new Intent(this, com.foo.bar.Settings.class);

And it worked. Of course, the other, and better, way to solve this particular issue would be to use better names for my activities.

HTH anyone with this variant of the problem.

Chalky answered 22/4, 2014 at 11:49 Comment(2)
In my case i had written the spelling of Activity wrongLegion
I had a PreferencesActivity and there seems to be an Android class of that name which had an include statement. Similar cause.Gouveia
R
4

Sometimes,It's due to existence of the same class name (second parameter of the Intent) in different packages.

I found also that this occurs when you call startService instead of calling startActivity and vice versa.

Rowe answered 11/9, 2017 at 0:55 Comment(0)
N
2

From your exception which one is your class - Facebook or Example Because, you declared in package in manifest as com.Android.myApp But, for facebook activity you declared com.android.myApp.Facebook.Example And,

If example is your activity means, you should declared your activity as com.Android.myApp.Facebook.Example Because, its from different package or your Activity name as Facebook.Example So better you can declare your Activity like below -

<activity
        android:name="com.Android.myApp.Facebook.Example"
        android:label="@string/app_name" />
Neckpiece answered 6/6, 2012 at 5:35 Comment(0)
T
2

This can happen on large projects when the cached manifest gets out of sync. I was able to fix it in the Android Studio terminal with ./gradlew clean and then in the Android Studio menu bar selecting File > Invalidate Caches / Restart for good measure

Transverse answered 19/2, 2019 at 2:13 Comment(0)
B
1

Just make sure your Activity is decorated with this attribute:

[Activity(Label = "Your App Name", MainLauncher=true)]

Note: Only Set MainLauncher if needed.

Boldt answered 3/5, 2016 at 15:10 Comment(0)
D
0

This works if you have an Activity object (which you need to launch):

 intent.setClassName(CallingActivity.this, activityToLaunch.getComponentName().getClassName());
Deauville answered 13/5, 2015 at 3:51 Comment(0)
C
0

You need to use this code if you wish to change your class dynamically from string: Intent intent = new Intent().setClassName(this.getPackageName(), "com.some.other.name"); or you can put result from array or any other instead of "com.some.other.name". Cheers!

Chaffer answered 15/9, 2019 at 21:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.