转自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 :
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 [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
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.
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.