In the following code i get a NullPointerException on lines 9/10 with findViewById().
In my main class I just instantiated an object from this class, to use .getFrom()
public class UserInteraction extends Activity {
EditText etFrom;
int from;
EditText etTill;
int till;
public UserInteraction(){
etFrom = (EditText)findViewById(R.id.et_from);
etTill = (EditText)findViewById(R.id.et_till);
}
public int getFrom() {
String s = etFrom.getText().toString();
int i = Integer.parseInt(s);
return i;
}
public int getTill() {
String s = etTill.getText().toString();
int i = Integer.parseInt(s);
return i;
}
Is it that the contentView is set in my main class ..?
What could be the cause ?
以上就是NullPointerException on findViewById() in android的详细内容,更多请关注web前端其它相关文章!