android.content.ActivityNotFoundException:

前端 未结 24 1875
一生所求
一生所求 2020-11-22 10:38

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

android.content.ActivityNotFoundExcept

相关标签:
24条回答
  • 2020-11-22 11:22

    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);
    }
    
    0 讨论(0)
  • 2020-11-22 11:25

    Check out the content of the Android Manifest File in the bin folder of the project. When your app is compiled and packaged the Manifest File is copied to the bin folder. In my case the Manifest in the bin folder did not agree with the original Manifest. This is probably a mistake of Eclipse. I manually copied the Manifest to the bin folder and it worked.

    0 讨论(0)
  • 2020-11-22 11:26

    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.

    0 讨论(0)
  • 2020-11-22 11:26

    you can add this code in manifiest.xml file

    action android:name="com.kaushalam.activity101activity.SecondActivity"
    category android:name="android.intent.category.DEFAULT"
    
    0 讨论(0)
  • 2020-11-22 11:27

    I had an ActivityNotFoundException when I implemented the Activity inside another class (as an inner class):

    //... inside the utility class Pref
    public static class Activity extends PreferenceActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.prefs);
        }
    }
    //...
    

    Declared as the following inside the manifest:

    <activity android:name=".Pref.Activity"
    ...
    

    After declaring this as a normal class (public class PrefActicity) and changing manifest accordingly, it worked as usual.

    0 讨论(0)
  • 2020-11-22 11:28

    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.

    0 讨论(0)
提交回复
热议问题