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.
精彩评论