java.lang.RuntimeException: Unable to instantiate activity ComponentInfo

前端 未结 30 2443
感动是毒
感动是毒 2020-11-22 15:15

I was trying to run a sample code While launching the application in the android 1.5 emulator , I got these errors.... Any one have some hint..?

ERROR from LogCat:<

相关标签:
30条回答
  • 2020-11-22 15:47

    I have tried all above solution but nothing work for me. after I have just add extend activity instead of AppCompatActivity and working fine.

    used

    public class MainActivity extends Activity  
    

    instead of

    public class MainActivity extends AppCompatActivity 
    

    i dont know what real issue was that.

    0 讨论(0)
  • 2020-11-22 15:48

    This happens to me fairly frequently when using the NDK. I found that it is necessary for me to do a "Clean" in Eclipse after every time I do a ndk-build. Hope it helps anyone :)

    0 讨论(0)
  • 2020-11-22 15:49

    I got rid of this problem by deleting the Bin and Gen folder from project(which automatically come back when the project will build) and then cleaning the project from ->Menu -> Project -> clean.

    Thanks.

    0 讨论(0)
  • 2020-11-22 15:50

    Got this problem, and fixed it by setting the "launch mode" property of the activity.

    0 讨论(0)
  • 2020-11-22 15:51

    This might not be relevant to the actual question, but in my instance, I tried to implement Kotlin and left out apply plugin: 'kotlin-android'. The error happened because it could not recognize the MainActivity in as a .kt file.

    Hope it helps someone.

    0 讨论(0)
  • 2020-11-22 15:52

    I encountered this problem too, but in a slightly different way. Here was my scenario:

    App detail:

    • Using ActionBarSherlock as a library
    • Using android-support-v4-r7-googlemaps.jar in the ActionBarSherlock library so I could use a "map fragment" in my primary project
    • Added the jar to the build path of my primary project
    • Included the <uses-library android:name="com.google.android.maps" /> in the manifests of both the library project and my primary project (this may not be necessary in the library?)
    • The manifest in the primary project had the proper activity definition and all of the appropriate properties
    • I didn't have an abstract activity or any of the other gotchas I've seen on Stack Overflow pertaining to this problem.

    However, I still encountered the error described in the original post and could not get it to go away. The problem though, was slightly different in one regard:

    • It only affected a fresh install of the application to my device. Any time the app installed for the first time, I would get the error preceded by several "warnings" of: Unable to resolve superclass of FragmentActivity
    • Those warnings traced back to the ActionBarSherlock library
    • The app would force close and crash.
    • If I immediately rebuilt and redeployed the app, it worked fine.
    • The only time it crashed was on a totally fresh install. If I uninstalled the app, built and deployed again from Eclipse, it would crash. Build/deploy a second time, it would work fine.

    How I fixed it:

    • In the ActionBarSherlock library project, I added the android-support-v4-r7-googlemaps.jar to the build path
    • This step alone did not fix the problem

    • Once the jar was added to the build path, I had change the order on the Java Build Path > Order and Export tab - I set the JAR to the first item in the list (it was the last after the /src and /gen items).

    • I then rebuilt and redeployed the app to my device - it worked as expected on a fresh install. Just to be certain, I uninstalled it again 2-3 times and reinstalled - still worked as expected.

    This may be a total rookie mistake, but I spent quite a while digging through posts and my code to figure it out, so hopefully it can be helpful to someone else. May not fix all situations, but in this particular case, that ended up being the solution to my problem.

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