views:

46

answers:

3

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

EditText username = (EditText)findViewById(R.id.usernameText);

the app crashes, why is this?

A: 

The view has not been inflated, or you are missing

setContentView(R.layout.layout_file);
Pentium10
A: 

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.

BrennaSoft
A: 

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.

LucaB