gpt4 book ai didi

java - 不兼容的类型 : View cannot be converted to LinearLayout

转载 作者:行者123 更新时间:2023-12-02 04:38:30 26 4
gpt4 key购买 nike

当我想要制作 Apk 文件时,出现 8 个错误,我希望有人帮助我修复它

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

失败:构建因异常而失败。

  • 出了什么问题:任务“:app:compileReleaseJavaWithJavac”执行失败。

    Compilation failed; see the compiler error output for details.

  • 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。使用 --scan 运行以获得完整的见解。

  • 获取更多帮助:https://help.gradle.org

34 秒内构建失败

最佳答案

您正在使用不兼容的变量初始化您的小部件(按钮,线性布局,...),您需要将它们转换为正确的小部件类型,我猜您正在以这种方式初始化您的小部件:

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

你应该这样做:

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

您的做法是错误的,但如果您使用的是 buildToolsVersion 26 或更高版本,则可以使用它们

关于java - 不兼容的类型 : View cannot be converted to LinearLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56533358/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com