Hi, Can you double-check the id of the Button? I don't think it's being found.
Cheers, James On Fri, Oct 2, 2009 at 3:18 PM, sbruno74 <sbrun...@gmail.com> wrote: > > It doesn't work. And I had to declare usernameView and passwordView > final in order to access them from within the inner class. It still > gives me the same error, and using logcat, it says it is a null > pointer exception on the line where I call setOnClickListener(). > > On Oct 2, 2:31 pm, Android_n00b <nikhil...@gmail.com> wrote: > > Try this and let me know if it works: > > > > public void onCreate(Bundle savedInstanceState) { > > super.onCreate(savedInstanceState); > > setContentView(R.layout.main); > > Button loginButton = (Button) findViewById(R.id.login); > > EditText usernameView = (EditText) > > findViewById > > (R.id.username); > > EditText passwordView = (EditText) > > findViewById > > (R.id.password); > > loginButton.setOnClickListener(new View.OnClickListener() { > > public void onClick(View v) { > > mUsername = usernameView.getText().toString > > (); > > mPassword = passwordView.getText().toString > > (); > > if (verifyLogin()) { > > callHome(); > > } > > } > > }); > > } > > > > On Oct 2, 12:15 pm, sbruno74 <sbrun...@gmail.com> wrote: > > > > > > > > > Hello, > > > > > I am working on a simple application that, for now, just presents a > > > login page as the starting activity with username and password and a > > > login button. When you click on the login button, it starts a new > > > activity after verifying credentials. When I run the application in > > > the emulator, it stops unexpectedly without even showing the main > > > activity with this error message : The application ... has stopped > > > unexpectedly. Please try again later. > > > > > It seems that it is the code where I register a listener for the > > > button click that causes the crash because when I comment the code, at > > > leas the application starts normally. I can't find the error. Here's > > > my onCreate method where I register the listener: > > > > > public void onCreate(Bundle savedInstanceState) { > > > super.onCreate(savedInstanceState); > > > setContentView(R.layout.main); > > > > > Button loginButton = (Button) findViewById(R.id.login); > > > > > loginButton.setOnClickListener(new View.OnClickListener() { > > > public void onClick(View v) { > > > EditText usernameView = (EditText) findViewById > > > (R.id.username); > > > EditText passwordView = (EditText) findViewById > > > (R.id.password); > > > mUsername = usernameView.getText().toString(); > > > mPassword = passwordView.getText().toString(); > > > if (verifyLogin()) { > > > callHome(); > > > } > > > } > > > }); > > > } > > > > > For now, verifyLogin() does nothing and just returns true. The callHome > > > () method just builds an intent, registers username and password as > > > extras and starts the other activity with the intent. > > > > > When I comment the setOnClickListener() call, I do not get the error. > > > > > Please what did I do wrong? > > > > > I run eclipse 3.5 with the ADT plugin on Windows Vista 64-bit. > > > > > Stéphane > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---