在控件TextView中添加自己的文字时遇到的问题
这个问题就是,我已经给myTextView建立了一个ID,但是在使用findViewById查找时遇到问题,将函数findViewById的返回值强行转化为TextView类,代码为TextView myTextView=(TextView)findViewById(R.id.myTextView);这行代码的两个TextView都显示TextView不能被解析成一个变量,我的SRC源文件如下
package hi.hello;
import android.app.Activity;
import android.os.Bundle;
public class HiActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView myTextView=(TextView)findViewById(R.id.myTextView);//从这里出现问题
myTextView.setText("我的第一个TextView");
}
}
Main.xml如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myTextView"/>
</LinearLayout>
R.JAVA如下
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package hi.hello;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int myTextView=0x7f050000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
不知问题出在哪里,我初学