android.content.ActivityNotFoundException, unable to start activity

Ferox picture Ferox · May 24, 2013 · Viewed 8.7k times · Source

I have a problem with the Manifest of my Application. Clicking on a button on Main activity I want to start an other Activity, so I used this function:

public void startDatacenters() {
    Intent intent = new Intent(context, Datacenters.class);
    activity.startActivity(intent);}

The package of Datacenters.class is com.eco4cloud.activities.Datacenters

So my manifest is this:

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".activities.Main"
            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=".activities.Datacenters"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.eco4cloud.activities.DATACENTERS" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
</application>

</manifest>

Android gave me this error i don't know why :(

05-24 18:01:32.622: D/AndroidRuntime(15404): Shutting down VM 05-24 18:01:32.622: W/dalvikvm(15404): threadid=1: thread exiting with uncaught exception (group=0x40a441f8) 05-24 18:01:32.632: E/AndroidRuntime(15404): FATAL EXCEPTION: main 05-24 18:01:32.632: E/AndroidRuntime(15404): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eco4cloud/com.eco4cloud.activities.Main}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.eco4cloud/com.eco4cloud.activities.Datacenters}; have you declared this activity in your AndroidManifest.xml? 05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2079) 05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104) 05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.ActivityThread.access$600(ActivityThread.java:132) 05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157) 05-24 18:01:32.632: E/AndroidRuntime(15404): at android.os.Handler.dispatchMessage(Handler.java:99) 05-24 18:01:32.632: E/AndroidRuntime(15404): at android.os.Looper.loop(Looper.java:137) 05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.ActivityThread.main(ActivityThread.java:4575) 05-24 18:01:32.632: E/AndroidRuntime(15404): at java.lang.reflect.Method.invokeNative(Native Method) 05-24 18:01:32.632: E/AndroidRuntime(15404): at java.lang.reflect.Method.invoke(Method.java:511) 05-24 18:01:32.632: E/AndroidRuntime(15404): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 05-24 18:01:32.632: E/AndroidRuntime(15404): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 05-24 18:01:32.632: E/AndroidRuntime(15404): at dalvik.system.NativeStart.main(Native Method) 05-24 18:01:32.632: E/AndroidRuntime(15404): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.eco4cloud/com.eco4cloud.activities.Datacenters}; have you declared this activity in your AndroidManifest.xml? 05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508) 05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384) 05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.Activity.startActivityForResult(Activity.java:3190) 05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.Activity.startActivity(Activity.java:3297) 05-24 18:01:32.632: E/AndroidRuntime(15404): at com.eco4cloud.controllers.MainController.startDatacenters(MainController.java:46) 05-24 18:01:32.632: E/AndroidRuntime(15404): at com.eco4cloud.activities.Main.verifyAndSignIn(Main.java:117) 05-24 18:01:32.632: E/AndroidRuntime(15404): at com.eco4cloud.activities.Main.onCreate(Main.java:53) 05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.Activity.performCreate(Activity.java:4465) 05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033) 05-24 18:01:32.632: E/AndroidRuntime(15404): ... 11 more

Someone can help me?? I don't know if the problem is with the package name or others things :(

Answer

Raghunandan picture Raghunandan · May 24, 2013

I am not sure what you are trying to do.

But a couple of suggestions to try.

    package="com.eco4cloud.activities" 
    // make sure package name is right.
    // probably it should be as above. 

Mention the package name as above

Since you have explicit intent you don't require a intent-filter

      // use this assuming Datacenters is in package com.eco4cloud.activities
      // also assuming package="com.eco4cloud.activities"
      <activity
        android:name=".Datacenters" 
        android:label="@string/app_name" >
    </activity>

If package="com.eco4cloud" try the below

       <activity
        android:name="com.eco4cloud.activities.Datacenters" 
        android:label="@string/app_name" >
    </activity> 

If you are starting a activity in a non-activity class

     public void startDatacenters() {
     Intent intent = new Intent(context, Datacenters.class);
     // assuming context is the activity content  
     context.startActivity(intent);
     //in your case you have activity.startActivity(intent)
     // not sure what activity is 
    }