Sunday 11 November 2012

Handling The android.content.ActivityNotFoundException: Unable to find explicit activity class


ActivityNotFoundException is the most common exception encountered while developing the android application. This can be compared to the class not found exception. We will see why this exception arises and how to deal with it.

Reason 1: Class Reference Not Mentioned in the AndroidManifest.xml  file
All the activities of our package must be mentioned in the manifest file otherwise the debugging of the application can not be done.This is done by adding the reference to the activity within the <activity></activity> tags .
Solution: Add the reference to the class in the manifest file by simply writing :

<activity android:name=".YourActivityName"></activity>

Reason 2: Syntax Error or Wrong Package Name Mentioned while Starting the New Activity
The correct naming of the package is important. Being a syntactical error this is not so dangerous.

Solution: Check the Package Name and write the following code for launching the new Activity

Intent launchNewIntent = new Intent(CurrentActivity.this,NewActivity.class);
    startActivityForResult(launchNewIntent, 0);


 Reason 3: Updates Not Installed: 
sometimes even if you have done all the coding correctly you still encounter this Exception.

Solution : Go to Help--->> Check For Updates---->>Install Updates(if you are prompted to install new updates)---->>Restart eclipse --->>Run your application again

No comments:

Post a Comment