8

I updated my android studio from 3.1.2 to 3.1.3 and updated my project sdk version to 28 and when i run the application it crashes as soon as it open and throws the following exception,

FATAL EXCEPTION: main
Process: com.google.android.apps.nexuslauncher, PID: 10288
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String)' on a null object reference
    at android.os.Parcel.createException(Parcel.java:1948)
    at android.os.Parcel.readException(Parcel.java:1865)
    at android.app.IActivityManager$Stub$Proxy.startActivity(IActivityManager.java:4541)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1660)
    at android.app.Activity.startActivityForResult(Activity.java:4574)
    at com.android.launcher3.Launcher.startActivityForResult(SourceFile:1394)
    at android.app.Activity.startActivity(Activity.java:4889)
    at com.android.launcher3.Launcher.startActivitySafely(SourceFile:2000)
    at com.android.launcher3.Launcher.startAppShortcutOrInfoActivity(SourceFile:1850)
    at com.android.launcher3.Launcher.onClick(SourceFile:1703)
    at android.view.View.performClick(View.java:6579)
    at android.view.View.performClickInternal(View.java:6556)
    at android.view.View.access$3100(View.java:777)
    at android.view.View$PerformClick.run(View.java:25660)
    at android.os.Handler.handleCallback(Handler.java:819)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
 Caused by: android.os.RemoteException: Remote stack trace:
    at android.app.LoadedApk.createAppFactory(LoadedApk.java:224)
    at android.app.LoadedApk.<init>(LoadedApk.java:152)
    at android.app.ActivityThread.getPackageInfo(ActivityThread.java:2043)
    at android.app.ActivityThread.getPackageInfo(ActivityThread.java:1998)
    at android.app.ActivityThread.getPackageInfo(ActivityThread.java:1970)
Zoe
  • 27,060
  • 21
  • 118
  • 148
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – ollaw Jun 17 '18 at 21:44
  • @Ollaw, not a duplicate at all. This exception is raised in the beginning of an app start. Even `onCreate()` is not called. I suppose, it's an API P emulator bug. – CoolMind Oct 26 '18 at 12:41

3 Answers3

7

It is a problem of API P emulator. On API 28, 27 it works right.

CoolMind
  • 26,736
  • 15
  • 188
  • 224
1

As CoolMind said, It is a problem in API P emulator, you can solve it by updating your Google APIs Intel System Image in Android SDK.

enter image description here

AliSh
  • 10,085
  • 5
  • 44
  • 76
  • 1
    Thanks! Sorry, I don't know who set minus to you. Cannot check your solution, as I already have installed this version. – CoolMind Apr 24 '19 at 08:04
-1

Add these two lines in your gradle.properties file and then build project. After i added these lines, Android Studio showed stacktrace in Logcat.I fixed those issues and then my app started working.

android.enableD8.desugaring = true
android.enableR8 = true
Umair Adil
  • 968
  • 1
  • 10
  • 24