Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.