java.lang.RuntimeException: Unable to instantiate activity ComponentInfo

前端 未结 30 2771
感动是毒
感动是毒 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: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 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.

提交回复
热议问题