Hi,

Am a total beginner and I was trying out to extrapolate on the Hello
Android code, but I've sort of hit a road block with a null pointer
exception. The code is as below:

public class HelloAndroid extends Activity
{
           @Override
           public void onCreate(Bundle icicle)
           {
               super.onCreate(icicle);

               setContentView(R.layout.screen1);

               Button btn = (Button) findViewById(R.id.hellobtn);
               btn.setOnClickListener(new View.OnClickListener() {
                     public void onClick(View view) {
                         setContentView(R.layout.screen2);
                     }
                 });
           }
}

As soon as I run this, the emulator gives me a null pointer exception.

The res/layout/screen1.xml and res/layout/screen2.xml are working
perfectly fine because when I just run
setContentView(R.layout.screen1) without the onClickListener, both the
screens work fine.

I suppose the null pointer exception pops in the onClick function.

Pls help!!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to