"The method findViewById(int) is undefined for ..."
2015-06-11 17:17
507 查看
转自http://www.anddev.org/-und-quotthe_method_findviewbyidint_is_undefined_for_-und-quot-t11806.html
my main class that the wizard set up for me, but i wanted to simplify the code by making all its actions in a new class.
I made the new class, and when i try to assign a TextView to a variable ...
example :
Syntax: [
Download ] [
Hide ]
Syntax: [
Download ] [
Show ]
Using java Syntax Highlighting
tv = (TextView)findViewById(R.id.TextView01);
Parsed in 0.030 seconds, using
GeSHi 1.0.8.4
i get the error:
The method findViewById(int) is undefined for the type newClass
I can make the error go away by making
Code:
Select all
but that gives me force close errors when i start the app. I am a novice programmer, but I am so confused, please help!
gooberguy
Junior Developer
Posts: 20Joined: Thu Mar 04, 2010 7:45 am
Top
Top
by
senormoll » Sat Mar 06, 2010 8:10 pm
It's difficult without seeing all of your code, please post a larger portion of it.
Just to speculate on some issues for now:
1) make sure your "main" class does extend Activity
2) make sure there is an element in main.xml or whatever layout you're using with the id TextView01
3) make sure you declare the element tv as a textview
So
public class MyClass extends Activity {
private TextView tv;
...
tv = (TextView) findViewById(R.id.TextView01);
}
Since you said you created your own class, I have a feeling it's one of those three issues.
my main class that the wizard set up for me, but i wanted to simplify the code by making all its actions in a new class.
I made the new class, and when i try to assign a TextView to a variable ...
example :
Syntax: [
Download ] [
Hide ]
Syntax: [
Download ] [
Show ]
Using java Syntax Highlighting
tv = (TextView)findViewById(R.id.TextView01);
Parsed in 0.030 seconds, using
GeSHi 1.0.8.4
i get the error:
The method findViewById(int) is undefined for the type newClass
I can make the error go away by making
Code:
Select all
public class newClass extends activity
but that gives me force close errors when i start the app. I am a novice programmer, but I am so confused, please help!
gooberguy
Junior Developer
Posts: 20Joined: Thu Mar 04, 2010 7:45 am
Top
Top
by
senormoll » Sat Mar 06, 2010 8:10 pm
It's difficult without seeing all of your code, please post a larger portion of it.
Just to speculate on some issues for now:
1) make sure your "main" class does extend Activity
2) make sure there is an element in main.xml or whatever layout you're using with the id TextView01
3) make sure you declare the element tv as a textview
So
public class MyClass extends Activity {
private TextView tv;
...
tv = (TextView) findViewById(R.id.TextView01);
}
Since you said you created your own class, I have a feeling it's one of those three issues.
相关文章推荐
- 使用svn删除Xcode工程中的文件
- DHCP (Dynamic Host Configuration Protocol)
- android手机使用ksoap2发送soap请求,服务端接收参数为null
- Android 通过图库选择图片提示找不到路径 open failed: EROFS (Read-only file system)
- jQuery选择器全面总结
- Leetcode[104]-Maximum Depth of Binary Tree
- java中的clone()方法的研究---(7)如何编写正确的clone()方法:Date, Timestamp
- 策略模式学习笔记
- 外汇牌价趋势波动图
- swift简介
- .net网站如何配置伪静态
- Java反射机制---用代码说话
- 网页动画的十二原则
- Multiply Strings——面试题
- 查询所有SQL用户的连接信息(可显示IP)\SQL Server中强制关闭数据库连接
- quick-cocos2dx使用windows下向导生成的IOS工程在MAC下编译报错的解决方法
- Mosquitto的安装、配置、测试
- [MySQL] 实现树形的遍历(关于多级菜单栏以及多级上下部门的查询问题)
- maven仓库快速镜像
- 策略模式学习笔记