Nikitc
Nikitc

Reputation: 815

Android studio doest not show error in kotlin class after update gradle plugin

I work in the Android 4.1.2 studio. I updated Gradle plugin

-        classpath 'com.android.tools.build:gradle:3.5.3'
+        classpath 'com.android.tools.build:gradle:4.1.2'

and

-distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

After that, I tried to build the apk, but the build failed due to errors in kotlin class, for example: "'handleMessage' overrides nothing " for Handler class, and "Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type" for intent.getParcelableExtra. The Android studio itself does not show me such errors in kotlin class. Can you tell me what this is related to and how I can enable the display of errors in android studio

I have tried rebuild, clean , invalidate & restart.

Upvotes: 0

Views: 134

Answers (1)

ping li
ping li

Reputation: 1456

Click the "Handler" to open the Decompiled Handler.class, search "handleMessage" in it, the new definition looks as below:

public void handleMessage(@NonNull Message msg) {
    throw new RuntimeException("Stub!");
}

So the argument msg has been changed to @NonNull. Therefore, to fix this issue, the original override statement

override fun handleMessage(message: Message?)

should be updated to remove the ? to match the function definition.

override fun handleMessage(message: Message)

Upvotes: 1

Related Questions