Android: Unable to instantiate activity / ClassNotFoundException

前端 未结 30 2820
粉色の甜心
粉色の甜心 2020-11-27 13:46

I recently published an app to the market and I\'m now getting an error by some user, the app presumably crashes right when it starts. Unfortunately I can\'t contact him dir

相关标签:
30条回答
  • 2020-11-27 14:28

    Delete BIN and GEN folder files. Rebuild, everything should work. Check if theres another error below the "unable to instantiate", sometimes another error is firing this (activity cant load because of something even if its class has been found.

    0 讨论(0)
  • 2020-11-27 14:29

    I just got the same error (Unable to instantiate activity...) with Opera Mini. Opera Mini was on SD card (moved to SD card in the app setting). The error seems to be related to the fact that I swapped the SD card yesterday. The device was shutdown, I copied all data from the old card over to the new card (with cp -a) and then inserted the new card and started the device again. Everything seems to work as expected, but I see now that all apps on the SD card crashes with the same error.

    • Device: HTC Desire HD (Android 2.2)
    • Old SDHC card: SanDisk 8GB class 4
    • New SDHC card: Kingston 16GB class 4

    So I would say that this is a an Android bug and not something that can be fixed by app developers.

    Also see: http://android-developers.blogspot.com/2010/07/apps-on-sd-card-details.html

    It has always been the case that when you swap SD cards on an Android device, if you physically copy the contents of the old card to the new one, the system will use the data on the new card as if nothing had changed. This is also true of apps which have been installed on the SD card."

    This seems to be incorrect.

    0 讨论(0)
  • 2020-11-27 14:29

    After spending 6 hours on this issue, found that it was a silly mistake. Apparently if you're defining your Application class in android manifest and you have enabled MultiDex enabled, you have to add that on Application Class. Here is example from my app.

    It only gave me error on devices running on < Android 5.0

    AndroidManifest.xml

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

    AppClass.java

    class AppClass : Application() {
        override fun onCreate() {
            super.onCreate()
        }
    
    
    
        override fun attachBaseContext(base: Context) {
            super.attachBaseContext(base)
            MultiDex.install(this)   //Don't forget this !!!!
        }
    
    }
    
    0 讨论(0)
  • 2020-11-27 14:32

    I solved this problems by selecting : Project->properties->order and export

    select the all external jar files. clean and build it solved the issue

    0 讨论(0)
  • 2020-11-27 14:32

    Since ADT update to revision 22 (May 2013) you have to check "Android Private Libraries" check box in Project -> Properties -> Java Build Path -> Order and Export in Eclipse for your older projects to get rid of this exception ...

    0 讨论(0)
  • 2020-11-27 14:33

    Maybe it is too late to solve your problem but hopefully it will help someone else.
    I had a similar problem and after many tries, I decided to delete R.java.
    That did the trick.

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