Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.RuntimeException: Unable to instantiate application com.todos.MyApplication: java.lang.ClassNotFoundException

W/dalvikvm(21732): threadid=1: thread exiting with uncaught exception (group=0x41d0cda0)
E/Drive.UninstallOperation( 1829): Package still installed com.todos
E/AndroidRuntime(21732): FATAL EXCEPTION: main
E/AndroidRuntime(21732): Process: com.todos, PID: 21732
E/AndroidRuntime(21732): java.lang.RuntimeException: Unable to instantiate application com.todos.MyApplication: java.lang.ClassNotFoundException: Didn't find class "com.todos.MyApplication" on path: DexPathList[[zip file "/data/app/com.todos-3.apk"],nativeLibraryDirectories=[/data/app-lib/com.todos-3, /vendor/lib, /system/lib]]
E/AndroidRuntime(21732): at android.app.LoadedApk.makeApplication(LoadedApk.java:507)
E/AndroidRuntime(21732): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4841)
E/AndroidRuntime(21732): at android.app.ActivityThread.access$1600(ActivityThread.java:174)
E/AndroidRuntime(21732): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1381)
E/AndroidRuntime(21732): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(21732): at android.os.Looper.loop(Looper.java:146)
E/AndroidRuntime(21732): at android.app.ActivityThread.main(ActivityThread.java:5731)
E/AndroidRuntime(21732): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(21732): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(21732): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
E/AndroidRuntime(21732): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
E/AndroidRuntime(21732): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(21732): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.todos.MyApplication" on path: DexPathList[[zip file "/data/app/com.todos-3.apk"],nativeLibraryDirectories=[/data/app-lib/com.todos-3, /vendor/lib, /system/lib]]
E/AndroidRuntime(21732): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
E/AndroidRuntime(21732): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
E/AndroidRuntime(21732): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
E/AndroidRuntime(21732): at android.app.Instrumentation.newApplication(Instrumentation.java:981)
E/AndroidRuntime(21732): at android.app.LoadedApk.makeApplication(LoadedApk.java:502)
E/AndroidRuntime(21732): ... 11 more
W/ActivityManager(  757):   Force finishing activity com.todos/.MainActivity
W/DropBoxManagerService(  757): Dropping: data_app_crash (1781 > 0 bytes)

My AndroidManifest looks like the following...

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

  <uses-sdk
      android:minSdkVersion="16"
      android:targetSdkVersion="22" />

  <application
    android:allowBackup="true"
    android:label="@string/app_name"
    android:icon="@mipmap/ic_launcher"
    android:theme="@style/AppTheme"
    android:name="com.todos.MyApplication">


    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>

    <activity
      android:name=".MainActivity"
      android:label="@string/app_name"
      android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
      <intent-filter>
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
  </application>

This started breaking when I added com.todos.MyApplication source file...

enter image description here

When I open the project in Android Studio and navigate to MyApplication.java I see the following...

enter image description here

like image 495
TheJediCowboy Avatar asked Sep 08 '16 04:09

TheJediCowboy


1 Answers

Are you still facing this issue?

I have resolved this issue by installing clean apk:

  1. First uninstall the previous installed APK.
  2. Then run the following the commands:
cd android
./gradlew clean
react-native run-android

Above commands will first go to the android folder, then clean the folder using ./gradlew clean, and then rebuild the react-native run-android command in the root of the project.

like image 75
Supermacy Avatar answered Sep 20 '22 15:09

Supermacy