您的位置:首页 > 其它

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


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: