开发者

Getting EditText field from XML

开发者 https://www.devze.com 2022-12-24 01:32 出处:网络
I have an activity in my app, when i call the line EditText开发者_JAVA百科 username = (EditText)findViewById(R.id.usernameText);

I have an activity in my app, when i call the line

EditText开发者_JAVA百科 username = (EditText)findViewById(R.id.usernameText);

the app crashes, why is this?


The view has not been inflated, or you are missing

setContentView(R.layout.layout_file);


Yeah either setContentView hasn't been called in onCreate of the activity, or else the view you are trying to get isn't an EditText. What is the Exception you are getting? If its ClassCast then its not an EditText.


Things to check as no more information is provided:

  • R.id.usernameText is a valid identifier in your layout
  • Your layout has been set as a content view

Also, if you can edit the post and add the log of what's messing up, it will be more easy to reply.

0

精彩评论

暂无评论...
验证码 换一张
取 消