"The method findViewById(int) is undefined for ..."

转自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
  1. 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 [b]extends activity[/b]



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
Junior Developer
 
Posts: 20
Joined: Thu Mar 04, 2010 7:45 am


Top




Top


Postby 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值