'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.
What went wrong: Execution failed for task ':app:compileReleaseJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 34s
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |