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. How to access storage by using API?

If I want to read/write external storage, like usb drive,
does Android provide this feature to do?

Or how do using Google API to read/write SDcard on Mobile?
Where to get sample code for this goal?

Thanks for your kindly help.

2. keypad stuff

Hi folks,

I just ported Linux and Android Donut to a new device, although I'm
still working on power management and a few other drivers, and had a
couple of questions.

1) Is there any sort of template for multi-tap keypads in the android
source? Possibly with auto-completion?

By multi-tap, I mean that each key has both a number and 3 letters,
and that you need to hit the key a certain number of times to get a
specific letter. This is what was on a lot of mobiles over the last
couple of decades.

2) Are the Android keypad requirements defined anywhere, in a nice,
clean list? (home key, back key, etc) Right now I can type as much as
I please, but I can't seem to get back to the previous screen or the
home screen, which has some disadvantages as you might guess ;-)




3. How to compile Android kernel with Ipv6?

4. memory leak in activity

5. How to launch my app if some one browses any xml file

6. Just for test, Please ignore

7. Browser issue when visiting YouTube