Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.content.ActivityNotFoundException:

I am getting this exception while I am trying to call an activity from another one. The complete exception is

android.content.ActivityNotFoundException:Unable to find explicit activity class {com.x.y/com.x.y.class};

I am doing an intent.setClass("com.x.y","com.x.y.className") where className is the name of my activity class and com.x.y is the package it resides in.

My AndroidManifest.xml has the following content:

<activity android:name="com.x.y.className" android:label="@string/app_name">

Am I missing anything?

like image 693
sharath Avatar asked Aug 08 '10 09:08

sharath


People also ask

What is ActivityNotFoundException?

android.content.ActivityNotFoundException. This exception is thrown when a call to Context#startActivity or one of its variants fails because an Activity can not be found to execute the given Intent.

How do I stop ActivityNotFoundException?

If you want to handle the Exception then you can use Try/Catch and handle it. And for solving this type of Exception you have to register your activity into Manifest file. No need to register every activity in to register file but yes when you use startActivity then you have to registered your Activity.


4 Answers

Maybe you need to check that you added the new activity to the manifest.xml file

Example:

<activity
      android:name=".className" 
      android:label="@string/app_name" > 
</activity>
like image 142
Mina Wissa Avatar answered Oct 18 '22 19:10

Mina Wissa


If other people are encountering something similar and arrive at this post, an issue I had may save you some time. May not be related to the OP's problem but def related to the ActivityNotFound exception.

I was trying to load an activity by using:

Intent intent = new Intent( this, class );

However I continuously kept getting the ActivityNotFoundException even though I had checked and rechecked the code multiple times.

This exception I was getting wasn't actually being caused by the intent but some code I was running inside the loaded activity throwing a RuntimeException. (my issue was caused by Typeface.createFromAsset())

It is possible you are running into a similar RuntimeException in your activity.

To see if this is the case, put your intent code in try catch blocks. Like so:

try {
    /* your code */
    ...
} catch ( ActivityNotFoundException e) {
    e.printStackTrace();
}

Run your app again, and check your LogCat, if it's the same issue, you'll get a RuntimeException with a "Caused By:" entry pointing to your actual issue.

I spent a good hour trying to figure this out. Hopefully this may save someone some time.

like image 34
thepearson Avatar answered Oct 18 '22 19:10

thepearson


The activity you are calling should appear not only in the Manifest for its own package, but in the Manifest for the CALLING package, too.

like image 14
Gangnus Avatar answered Oct 18 '22 19:10

Gangnus


Delete your activity from the manifest and then add it again. This type do not write type the XML directly. Instead, go to Application > Application nodes > add, choose the Activity, and then browse for the file source.

This worked for me.

like image 8
bicha Avatar answered Oct 18 '22 18:10

bicha