You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio中XML与Java文件出现idLLScore相关报错如何解决?

问题原因及修复方案

1. XML布局报错修复

你这处报错是因为LinearLayout标签的属性写在了标签闭合符号之外,语法不合法:
原错误代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    android:id="@+id/idLLScore">

正确写法是把android:id属性移到LinearLayout标签内部,不要提前闭合标签:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/idLLScore">

2. Java文件id找不到报错修复

这处是因为引用id时大小写不匹配:
你XML中定义的id是idLLScore(S大写),但Java第88行写的是R.id.idLLscore(s小写),修改为一致即可:

View bottomSheetView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.score_bottom_sheet,(LinearLayout)findViewById(R.id.idLLScore));

其他潜在问题修复(避免后续运行崩溃)

  • 你在类中已经声明了questionTV、questionNumberTV、option1Btn~option4Btn全局变量,但在onCreate中又重新声明了局部的同名变量,会导致全局变量没有被初始化,后续setDataToViews方法调用时会空指针,把onCreate里这些变量前的类型声明去掉即可:
    // 错误写法
    TextView questionTV = findViewById(R.id.idTVQuestion);
    TextView questionNumberTV = findViewById(R.id.idTVQuestionAttempted);
    Button option1Btn = findViewById(R.id.idBtnOption1);
    Button option2Btn = findViewById(R.id.idBtnOption2);
    Button option3Btn = findViewById(R.id.idBtnOption3);
    Button option4Btn = findViewById(R.id.idBtnOption4);
    
    // 正确写法
    questionTV = findViewById(R.id.idTVQuestion);
    questionNumberTV = findViewById(R.id.idTVQuestionAttempted);
    option1Btn = findViewById(R.id.idBtnOption1);
    option2Btn = findViewById(R.id.idBtnOption2);
    option3Btn = findViewById(R.id.idBtnOption3);
    option4Btn = findViewById(R.id.idBtnOption4);
    
  • 类中无用的声明private Object LinearLayout;可以直接删除,避免命名冲突。

内容的提问来源于stack exchange,提问作者BananaSweden

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 13:09:03