尝试调用虚方法' java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String)'在null对象引用上

时间:2018-06-17 21:36:56

标签: java android

我将我的Android工作室从3.1.2更新到3.1.3并将我的项目sdk版本更新为28,当我运行应用程序时,它会在打开时崩溃并抛出以下异常,

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)

3 个答案:

答案 0 :(得分:5)

这是API P仿真器的问题。在API 28、27上可以正常使用。

答案 1 :(得分:-1)

在您的 gradle.properties 文件中添加这两行,然后构建项目。添加这些行后,Android Studio在Logcat中显示了stacktrace.I解决了这些问题,然后我的应用程序开始运行。

android.enableD8.desugaring = true
android.enableR8 = true

答案 2 :(得分:-1)

正如CoolMind所说,这是API P模拟器中的问题,您可以通过在Android SDK中更新Google API Intel System Image来解决。

enter image description here