java - Null Pointer Exception within Android Studio -


this question has answer here:

new android here. looked through other answers, still couldn't figure out wrong... hoping here. :)

android studio says there null object reference @ line 28 login.setonclick... line.

again, sorry if code mess, kinda winging it!

thanks in advance!

public class loginscreen extends actionbaractivity {      // edittext medit;     // textview mtext;      private static string artist = "artist";      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_login_screen);          button login = (button) findviewbyid(r.id.button1);         final edittext user = (edittext) findviewbyid(r.id.username);          login.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                  // mtext = (textview)findviewbyid(r.id.welcome);                 // mtext.settext("welcome "+medit.gettext().tostring()+"!");                  artist = user.gettext().tostring();                  intent intent = new intent(getapplicationcontext(), songselection.class);                 startactivity(intent);             }         });     }      public static string getartist(){         return artist;     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.menu_login_screen, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();          //noinspection simplifiableifstatement         if (id == r.id.action_settings) {             return true;         }          return super.onoptionsitemselected(item);     } } 

findviewbyid() method returns null in case activity missing view id passed. check whether layout activity_login_screen contains view id button1


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -