android.content.ActivityNotFoundException:

Viewed 71613

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?

24 Answers

My solution to this error was to add a package name in front of the name in manifest.

I had the following activities:

  • id.scanner.main.A1

  • id.scanner.main.gallery.A2

My manifest contained the following:

<activity android:name=".A1" ....></activity>
<activity android:name=".A2" ....></activity>

This solved the problem:

<activity android:name=".A1" ....></activity>
<activity android:name="gallery.A2" ....></activity>

I also ran into ActivityNotFoundException by passing the wrong view into setContentView(), each activity's class file must correspond with the layout xml file this way.

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.wrongView);
}

as opposed to

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.correctView);
}
Related