Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Alex Atwater
Alex Atwater
2,624 Points

Can’t .setText() of a EditText (text box)

Here is the onCreate

‘’’java protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_admin); if (savedInstanceState == null) { getFragmentManager().beginTransaction() .add(R.id.container, new PlaceholderFragment()).commit(); }

    Log.d("checkpoint", "1");
    //if there is a previous successful login, autofill username
    Log.d("checkpoint", "2");
    SharedPreferences prefs = getPreferences(MODE_PRIVATE); 
    Log.d("checkpoint", "3");
    final String restoredUsername = prefs.getString("adminusername","");
    if(!restoredUsername.equalsIgnoreCase(""))
      {
          Log.d("checkpoint", "5");
          final EditText adminUsername = (EditText)findViewById(R.id.adminusername);
          Log.d("checkpoint", "6");
          Log.d("username", restoredUsername);
          adminUsername.setText(restoredUsername);    
          Log.d("checkpoint", "7");
      }


}

‘’’ restoredUsername comes in perfect, i checked. Nothing wrong with that. I get the checkpoint 6 then the app crashes. I don’t understand and i’m stuck , please help.

One other note, i have a hint on the edit text if that makes a difference.