转自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 :
-
tv = (TextView )findViewById (R. id. TextView01 ) ;
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
- Posts: 20
- Joined: Thu Mar 04, 2010 7:45 am
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.

1190




被折叠的 条评论
为什么被折叠?



