Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4574742
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:57:55+00:00 2026-05-21T19:57:55+00:00

i would like to start a new activity according to the radiobutton that the

  • 0

i would like to start a new activity according to the radiobutton that the user choose.this is my non working code(i m using a toast message for now instead of a new activity)

public class cafechoice  extends Activity {   

    /** Called when the activity is first created. */
public RadioButton rb1;
public RadioButton rb2;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.cafechoice);

        final RadioButton rb1 = (RadioButton) findViewById(R.id.radio_red);
        final RadioButton rb2 = (RadioButton) findViewById(R.id.radio_blue);
        rb1.setOnClickListener(radio_listener);
        rb2.setOnClickListener(radio_listener);

}
    OnClickListener radio_listener = new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
             if(v == radio_listener)
            {

            if(rb1.isChecked() == true){Toast.makeText(cafechoice.this, 1, Toast.LENGTH_SHORT).show();}
            if(rb2.isChecked() == true){Toast.makeText(cafechoice.this, 1, Toast.LENGTH_SHORT).show();}
            }
    }
    };

}

@rekaszeru this is my logcatview

05-02 17:16:28.206: WARN/dalvikvm(678): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
05-02 17:16:28.216: ERROR/AndroidRuntime(678): Uncaught handler: thread main exiting due to uncaught exception
05-02 17:16:28.248: ERROR/AndroidRuntime(678): java.lang.RuntimeException: Unable to start activity ComponentInfo{kostas.menu.chania/kostas.menu.chania.cafechoice}: java.lang.NullPointerException
05-02 17:16:28.248: ERROR/AndroidRuntime(678):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481)
05-02 17:16:28.248: ERROR/AndroidRuntime(678):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2497)
05-02 17:16:28.248: ERROR/AndroidRuntime(678):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
05-02 17:16:28.248: ERROR/AndroidRuntime(678):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1848)
05-02 17:16:28.248: ERROR/AndroidRuntime(678):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-02 17:16:28.248: ERROR/AndroidRuntime(678):     at android.os.Looper.loop(Looper.java:123)
05-02 17:16:28.248: ERROR/AndroidRuntime(678):     at android.app.ActivityThread.main(ActivityThread.java:4338)
05-02 17:16:28.248: ERROR/AndroidRuntime(678):     at java.lang.reflect.Method.invokeNative(Native Method)
05-02 17:16:28.248: ERROR/AndroidRuntime(678):     at java.lang.reflect.Method.invoke(Method.java:521)
05-02 17:16:28.248: ERROR/AndroidRuntime(678):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-02 17:16:28.248: ERROR/AndroidRuntime(678):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-02 17:16:28.248: ERROR/AndroidRuntime(678):     at dalvik.system.NativeStart.main(Native Method)
05-02 17:16:28.248: ERROR/AndroidRuntime(678): Caused by: java.lang.NullPointerException
05-02 17:16:28.248: ERROR/AndroidRuntime(678):     at kostas.menu.chania.cafechoice.onCreate(cafechoice.java:24)
05-02 17:16:28.248: ERROR/AndroidRuntime(678):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-02 17:16:28.248: ERROR/AndroidRuntime(678):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2444)
05-02 17:16:28.248: ERROR/AndroidRuntime(678):     ... 11 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:57:55+00:00Added an answer on May 21, 2026 at 7:57 pm

    You should rather use a checkedChangeListener:

    final CompoundButton.OnCheckedChangeListener radio_listener = 
        new CompoundButton.OnCheckedChangeListener()
    {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
        {
            if (!isChecked)
                return;
            if (buttonView.getId() == R.id.radio_red)
                Toast.makeText(cafechoice.this, 1, Toast.LENGTH_SHORT).show();
            else if (buttonView.getId() == R.id.radio_blue)
                Toast.makeText(cafechoice.this, 1, Toast.LENGTH_SHORT).show();
        }
    };
    

    and in your onCreate method:

    rb1.setOnCheckedChangeListener(radio_listener);
    rb2.setOnCheckedChangeListener(radio_listener);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ViewPagerExtensions . I would like to start a new activity in each
In an given Android activity, I would like to start a new activity for
I would like to Start a new activity from my custom dialog, I have
I would like to start a new activity for a result , with startActvityForResult()
I would like to do this: From activity A start activity B. In activity
In an given Android activity, I would like to start a new activity for
I am trying to start a new project (asp.net MVC) and I would like
I would like to start making code patches to Rails. Are there any good
I would like to start a personal project that will give me a lot
I would like to start a broadcast receiver from an activity. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.