Newbie doubt here! Please advise.

by Vijay » Fri, 20 Feb 2009 13:22:16 GMT

Sponsored Links
I just started programmind an application using Eclipse for Android.
I am creating 2 screens.

1st screen:
Has a text and
a button which onClick --> takes you to the 2nd screen.

2nd screen:
Has a text and
a button which onClick -- > takes you to the 1st screen.

just like NEXT and BACK.

But somehow i keep getting "Application Simple application has stopped
unexpectedly." Force Close.


package com.vijay.simple;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Simple extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

    Button b1 = (Button) findViewById(;

    Button b2 = (Button) findViewById(;

    private OnClickListener buttonListener1 = new OnClickListener(){
        public void onClick(View v1){

    private OnClickListener buttonListener2 = new OnClickListener(){
        public void onClick(View v2){



Newbie doubt here! Please advise.

by lorenz » Sat, 21 Feb 2009 01:49:29 GMT


The problem is that your reference b2 is null and you get a
NullPointerException when trying to register the OnClickListener on
it. This happens because b2 does not yet exist when you ask for it by
calling findViewById(, for only the contents of your
main.xml file is already loaded in the onCreate() method.

However, I'm not sure if you should handle two "pages" in the same
class, since these are actually two activities. Maybe you want to
consider writing two different activities and then the buttons can
start them using Activity.startActivity(Intent).

Hope this helps ;-)


Sponsored Links

Other Threads

1. Drawing

Hi Sonic,

you can use canvas.drawCircle() and can draw in onDraw() method.


2. window.requestFeature(Window.FEATURE_RIGHT_ICON) does not work correctly

Hi all,

  i want to keep cancel button in the title bar at the right side, for
that I had used following code,


but i am getting the icon at the left side of title bar.

Is this a bug or something else is required to accomplish this?



3. Switching to Terrainview in Google Maps?

4. Any API to get the time elapsed since the system was started?

5. How does surface flinger access the data sent by MIO

6. Root G1 anda! (new & faster method)

7. LayoutParams.ScreenBrightness problem