Android Studio Kotlin代码建议IDE致命错误

时间:2018-09-12 20:59:27

标签: android android-studio kotlin

Android Studio 3.1.4中针对Kotlin的代码建议会产生致命错误。

示例应用程序如下(所有其他内容均为默认值):

activity_main.xml

<android.support.constraint.ConstraintLayout ...>
    <TextView .../>
    <Button ...
        android:onClick="clr" />
</android.support.constraint.ConstraintLayout>

MainActivity.kt((仅为默认值))

,因此xml上的onClick显示建议“在MainActivity中创建clr(View)”。但是,在单击建议时,会弹出IDE致命错误

org.jetbrains.kotlin.asJava.classes.KtLightClassImpl
com.intellij.util.IncorrectOperationException: org.jetbrains.kotlin.asJava.classes.KtLightClassImpl
    at com.intellij.psi.impl.light.LightElement.add(LightElement.java:139)
    at org.jetbrains.android.dom.AndroidCreateOnClickHandlerAction.addHandlerMethod(AndroidCreateOnClickHandlerAction.java:152)
    at org.jetbrains.android.dom.AndroidCreateOnClickHandlerAction.lambda$addHandlerMethodAndNavigate$2(AndroidCreateOnClickHandlerAction.java:170)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1003)
    at org.jetbrains.android.dom.AndroidCreateOnClickHandlerAction.addHandlerMethodAndNavigate(AndroidCreateOnClickHandlerAction.java:169)
    at org.jetbrains.android.inspections.AndroidMissingOnClickHandlerInspection$MyQuickFix.invoke(AndroidMissingOnClickHandlerInspection.java:284)
    at com.intellij.codeInsight.intention.impl.IntentionActionWithTextCaching$MyIntentionAction.invoke(IntentionActionWithTextCaching.java:181)
    at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.lambda$invokeIntention$3(ShowIntentionActionsHandler.java:209)
    at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.invokeIntention(ShowIntentionActionsHandler.java:213)
    at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.lambda$null$1(ShowIntentionActionsHandler.java:186)
    at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:88)
    at com.intellij.openapi.application.TransactionGuardImpl.submitTransactionAndWait(TransactionGuardImpl.java:153)
    at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.lambda$chooseActionAndInvoke$2(ShowIntentionActionsHandler.java:185)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:149)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:109)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:99)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:85)
    at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.chooseActionAndInvoke(ShowIntentionActionsHandler.java:184)
    at com.intellij.codeInsight.intention.impl.IntentionListStep.lambda$applyAction$1(IntentionListStep.java:293)
    at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:195)
    at com.intellij.ui.popup.AbstractPopup.lambda$null$7(AbstractPopup.java:1431)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
    at java.awt.EventQueue.access$500(EventQueue.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:715)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:732)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:822)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:650)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:366)
    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)

现在就可以在MainActivity.kt中手动创建单击功能。希望可以解决此问题

1 个答案:

答案 0 :(得分:0)

这是IntelliJ IDEA的Kotlin插件中不受支持的功能;您无法采取任何措施将其固定在自己的身边。我已经在问题跟踪器中提交了bug report