NullPointerException on findViewById() in android

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(; etTill = (EditText)findViewById(; } 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前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准