2

So I have this code: android studio marks casts as redundant.

But if I remove casts I will get compile error:

Error:(42, 29) Type mismatch: cannot convert from View to Button

Error:Execution failed for task ':app:transformJackWithJackForDebug'. com.android.build.api.transform.TransformException: com.android.builder.core.JackToolchain$ToolchainException: Jack compilation exception

What am I doing wrong? Android Studio v2.3.3

Community
  • 1
  • 1

3 Answers3

1

The declaration of View#findViewById on Android <= 25 is

View findViewById(int resId);

Requiring explicit cast for usage.

While the declaration on Android >= 26

<T> T findViewById(int resId);

It does the unsafe cast for you and returns the expected value for the assignment.

If you compile level is 26 you will be using the new method.

Marcos Vasconcelos
  • 18,038
  • 29
  • 106
  • 167
0

Probably the elem with Id buttonLoad is not a Button but a View.

Provide the code of the layout if it isn't the solution

bra_racing
  • 622
  • 1
  • 9
  • 30
0

So the solution was just cleaning up and rebuilding the project. Thanks to Fatih Ozcan