AbdEssamad Hayani
AbdEssamad Hayani

Reputation: 1

incompatible types: View cannot be converted to LinearLayout

When I want to make Apk file I get 8 errors, I hope someone helps me to fix it

Task :app:compileReleaseJavaWithJavac FAILED C:\Codes\code\app\src\main\java\com\insta\followers\TagsActivity.java:61: error: incompatible types: View cannot be converted to LinearLayout unitBanner = findViewById(R.id.unitads); ^ C:\Codes\code\app\src\main\java\com\insta\followers\HelpActivity.java:32: error: incompatible types: View cannot be converted to LinearLayout unitBanner = findViewById(R.id.unitads); ^ C:\Codes\instagram hashTags\app\src\main\java\com\insta\followers\MainActivity.java:57: error: incompatible types: View cannot be converted to LinearLayout unitBanner = findViewById(R.id.unitads); ^ C:\Codes\code\app\src\main\java\com\insta\followers\MainActivity.java:109: error: incompatible types: View cannot be converted to LinearLayout rate = findViewById(R.id.rate); ^ C:\Codes\code\app\src\main\java\com\insta\followers\MainActivity.java:110: error: incompatible types: View cannot be converted to LinearLayout share = findViewById(R.id.share); ^ C:\Codes\code\app\src\main\java\com\insta\followers\MainActivity.java:111: error: incompatible types: View cannot be converted to LinearLayout settings = findViewById(R.id.settings); ^ C:\Codes\code\app\src\main\java\com\insta\followers\SettingsActivity.java:58: error: incompatible types: View cannot be converted to LinearLayout unitBanner = findViewById(R.id.unitads); ^ C:\Codes\code\app\src\main\java\com\insta\followers\Splash.java:50: error: incompatible types: View cannot be converted to Button start = findViewById(R.id.start); ^ 8 errors

FAILURE: Build failed with an exception.

BUILD FAILED in 34s

Upvotes: 0

Views: 684

Answers (1)

ismail alaoui
ismail alaoui

Reputation: 6073

your are initializing your widget (button , linearlayout, .... ) with incompatible variable , you need to cast them to the right widget type , i guess you are initializing your widgets this way :

Button start = findViewById(R.id.start) ; 

and you should do this :

Button start = (Button) findViewById(R.id.start) ; 

the way you are doing it is wrong , but you can use them if you are using buildToolsVersion 26 or higher

Upvotes: 1

Related Questions