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

Android Studio中按钮修改TextView文本时出现Cannot resolve symbol错误求助

求助:Android Studio修改TextView文本时遇Cannot resolve symbol错误

大家好!我是一名本科大一学生,最近在开发一款数独APP,结果卡在了一个技术问题上:在Android Studio里通过按钮修改TextView文本时,一直出现Cannot resolve symbol错误,我完全摸不着头绪,希望能得到大家的帮助🙏

下面是我的相关代码:

TextView的XML代码

<TextView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/change" android:text="Not Changed"/>

按钮的XML代码

<Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="24dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:text="Test Button" app:layout_constraintBottom_toTopOf="@+id/btn_sample" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" />

对应的Java代码

public void btn(View view) { TextView t=(TextView)findViewById(change); t.setText("Changed"); }

如果能解决这个问题,对我和一起做项目的同学来说会是很大的激励!我是编程新手,英文也不太好,提前谢谢大家的帮助啦🥺


更新:问题已经解决啦!

特别感谢nilesh-rathod的帮助,修正后的代码如下:

修正后的按钮XML代码

<Button android:id="@+id/btn" android:onClick="btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="24dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:text="Test Button" app:layout_constraintBottom_toTopOf="@+id/btn_sample" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" />

修正后的Java代码

public void btn(View view) { TextView t=(TextView)findViewById(R.id.change); t.setText("Changed"); }

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 09:50:44