gpt4 book ai didi

android - TextView1 无法解析为类型

转载 作者:行者123 更新时间:2023-11-29 14:52:16 26 4
gpt4 key购买 nike

我正在尝试完成有关可编辑在 main.xml 中声明的文本的教程,

eclipse 说:

-TextView1 can't be resolved to a type

-TextView2 can't be resolved to a type

-TextView1 can't be resolved to a variable

-TextView2 can't be resolved to a variable

-TextView1 can't be resolved

-TextView2 can't be resolved

这是我的代码:

package marco.prova;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Main extends Activity {
private TextView1 textView1;
private TextView2 textView2;

/** Called when the activity is first created.*/

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

TextView1 = (TextView) findViewById(R.id.testo1);
TextView1.setText("Testo modificato tramite codice 1");

TextView2 = (TextView) findViewById(R.id.testo2);
TextView2.setText("Testo modificato tramite codice 2");
}
}

感谢您的帮助。

最佳答案

TextView1TextView2 不是 Android 类,但是 TextView 是。所以首先修复你的变量声明:

private TextView textView1;
private TextView textView2;

然后修正你的变量赋值和变量使用(注意小写):

textView1 = (TextView) findViewById(R.id.testo1);
textView1.setText("Testo modificato tramite codice 1");

textView2 = (TextView) findViewById(R.id.testo2);
textView2.setText("Testo modificato tramite codice 2");

关于android - TextView1 无法解析为类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14539365/

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