单击 运行 和调试按钮会在 Android Studio 中引发 NullPointerException

Clicking Run and debug buttons raise NullPointerException inside Android Studio

我无法 运行 我的任何项目,因为单击 rundebug 按钮(或按它们各自的快捷键)将引发以下 NPE 并询问我报告给 google.

此错误发生在 Android Studio 中,而不是在我的代码中;不需要示例代码来重现,因为它可能发生在任何项目中。

java.lang.NullPointerException
at com.intellij.openapi.vfs.impl.local.LocalFileSystemBase.findFileByIoFile(LocalFileSystemBase.java:79)
at com.intellij.openapi.vfs.VfsUtil.findFileByIoFile(VfsUtil.java:232)
at com.android.tools.idea.model.ManifestInfo$ManifestFile.getLibManifests(ManifestInfo.java:406)
at com.android.tools.idea.model.ManifestInfo$ManifestFile.refresh(ManifestInfo.java:339)
at com.android.tools.idea.model.MergedManifest.syncWithReadPermission(MergedManifest.java:377)
at com.android.tools.idea.model.MergedManifest.run(MergedManifest.java:356)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:843)
at com.android.tools.idea.model.MergedManifest.sync(MergedManifest.java:353)
at com.android.tools.idea.model.MergedManifest.getActivities(MergedManifest.java:510)
at com.android.tools.idea.run.activity.DefaultActivityLocator.lambda$computeDefaultActivity[=12=](DefaultActivityLocator.java:79)
at com.intellij.openapi.project.DumbService.run(DumbService.java:89)
at com.intellij.openapi.project.DumbService.compute(DumbService.java:125)
at com.intellij.openapi.project.DumbService.compute(DumbService.java:119)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:859)
at com.intellij.openapi.project.DumbService.runReadActionInSmartMode(DumbService.java:119)
at com.intellij.openapi.project.DumbService.runReadActionInSmartMode(DumbService.java:86)
at com.android.tools.idea.run.activity.DefaultActivityLocator.computeDefaultActivity(DefaultActivityLocator.java:78)
at com.android.tools.idea.run.activity.DefaultActivityLocator.validate(DefaultActivityLocator.java:65)
at com.android.tools.idea.run.editor.DefaultActivityLaunch$State.checkConfiguration(DefaultActivityLaunch.java:49)
at com.android.tools.idea.run.AndroidRunConfiguration.checkConfiguration(AndroidRunConfiguration.java:108)
at com.android.tools.idea.run.AndroidRunConfigurationBase.validate(AndroidRunConfigurationBase.java:175)
at com.android.tools.idea.run.AndroidRunConfigurationBase.checkConfiguration(AndroidRunConfigurationBase.java:113)
at com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl.checkSettings(RunnerAndConfigurationSettingsImpl.java:423)
at com.intellij.execution.impl.RunManagerImpl.canRunConfiguration(RunManagerImpl.java:535)
at com.intellij.execution.impl.RunManagerImpl.canRunConfiguration(RunManagerImpl.java:530)
at com.intellij.execution.ProgramRunnerUtil.executeConfiguration(ProgramRunnerUtil.java:71)
at com.intellij.execution.impl.ExecutionManagerImpl.start(ExecutionManagerImpl.java:117)
at com.intellij.execution.impl.ExecutionManagerImpl.access0(ExecutionManagerImpl.java:67)
at com.intellij.execution.impl.ExecutionManagerImpl.run(ExecutionManagerImpl.java:509)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:222)
at com.intellij.util.Alarm$Request.run(Alarm.java:378)
at com.intellij.openapi.application.TransactionGuardImpl.run(TransactionGuardImpl.java:291)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.runNextEvent(LaterInvocator.java:326)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:310)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access0(EventQueue.java:97)
at java.awt.EventQueue.run(EventQueue.java:709)
at java.awt.EventQueue.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:795)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:631)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:387)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

我刚刚注意到 Java 没有在我的机器上 运行ning。这就是问题的根源。

我有一台 Macbook pro,当我 运行 Android Studio 时,Java 的图标将添加到 docker。不知道为什么这次没有自动启动,很奇怪。因此,我不得不按下同步项目(虽然项目已经同步)只是为了强制 Java 到 运行!然后,通常的图标被添加到 docker 并且一切正常!

有类似的问题,但这是因为我在尝试在物理设备上调试时将构建变体设置为“发布”。切换到“调试”,一切又开始 运行 顺利了。