这个问题就是,我已经给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.com/apk/res/android"
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;
}
}
不知问题出在哪里,我初学
这行代码的两个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.com/apk/res/android"
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;
}
}
不知问题出在哪里,我初学
解决方案 »
- 如何保存GestureLibrary对象
- 自己编译android2.2源码生成sdk,使用时sdcard不能用,什么权限都没有。
- [求助]android里如何获得短信中心的号码
- 关于手机喇叭音效
- 一枚热爱计算机的大专应届毕业生, 真心请求看到这个标题的朋友进来一叙
- android客户端从服务器端下载文件
- Android后台发送短信后,如何判断短信发送成功或者发送失败?
- aidl数据库查询的问题
- mediaplayer 怎么避免出现anr
- Android分包为什么会一下子分出10个dex
- 开发个类似微博或论坛的应用,怎么开发啊
- Fedora 16 编译 android (2.3),求详细资料,谢谢!
import android.widget.TextView;