2017-10-18 77 views
2

所以我有這樣的代碼: android studio marks casts as redundant.Android的工作室標記findviewbyid投下多餘的,但它們不是

但如果我刪除蒙上我會得到編譯錯誤:

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

我在做什麼錯? Android Studio v2.3.3

+0

默認方法是保留compileSdkVersion 26之前需要的轉換。如果將compileSdkVersion設置爲26,則不需要使用轉換。 – Thracian

+0

@FatihOzcan我與compileSdkVersion 26有這個問題。 – Daniil

+1

嘗試清理和重建你的項目,它可能會有所幫助。 – Thracian

回答

0

可能與Id buttonLoad元素不是一個按鈕,而是一個視圖。

提供佈局的代碼,如果它不是解決

+0

這是一個按鈕,我猜:[截圖](https://imgur.com/NzodIlz) – Daniil

1

查看#findViewById Android上< = 25的聲明是

View findViewById(int resId); 

要求對使用顯式類型轉換。

雖然Android上的宣言> = 26

<T> T findViewById(int resId); 

它確實不安全投給你,並返回分配的預期值。

如果您編譯的級別是26,您將使用新的方法。