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 7646787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:17:51+00:00 2026-05-31T10:17:51+00:00

I have a Options Activity , where I select the color using a RadioButton

  • 0

I have a Options Activity, where I select the color using a RadioButton. By default, the White color is set android:checked="true". Now when I reach to my Canvas,I need to change the Paint color dynamically depending on which RadioButton was selected.
Here’s the code that I have tried:

            String radioButtonSelected = "";
            switch (checkedRadioButton) {
              case R.id.CheckRed : radioButtonSelected = "Red";
                                              break;
              case R.id.CheckBlue : radioButtonSelected = "Blue";
                                          break;
              case R.id.CheckWhite : radioButtonSelected = "White";
                                          break;
            }
            Intent i = new Intent(HandwritingRecognitionOptionTab.this,HandwritingRecognitionCanvas.class);
            i.putExtra("setColor",radioButtonSelected);
            //startActivity(i); // because I don't want to start the activity immediately after this

In the class for Canvas:

        Bundle getValue = getIntent().getExtras();
        drawColor = getValue.getString("setColor");
        if(drawColor.equals("White"))
            intColor = 1;
        if(drawColor.equals("Red"))
            intColor = 2;
        if(drawColor.equals("Blue"))
            intColor = 3;


        mPaint = new Paint();
        mPaint.setDither(true);
        mPaint.setColor(Color.WHITE);
        if(intColor == 1)
            mPaint.setColor(Color.WHITE);
        if(intColor == 2)
            mPaint.setColor(Color.RED);
        if(intColor == 3)
            mPaint.setColor(Color.BLUE);

But I get a NullPointerException whenever the Activity for Canvas is started. It is important to note that by default White should be the color. Also, this doesn’t store it persistently right? Should I look into SharedPreferences for this ?

  • 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-31T10:17:52+00:00Added an answer on May 31, 2026 at 10:17 am

    After reading through your comments it looks like that you are not starting the other activity using the given Intent and hence the NullPointerException as the Bundle wont be containg the same string in the next activity.

    You can opt out for the following options:

    1> Shared Prefrences (As highlighted by you)
    2> Some DB entry.
    3> Some file storage
    4> Singleton pattern
    

    but for me the best one would have been a shared prefrence. You might also want to have a look at this link for a detail

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have writen options to a <select> using something like Id.innerHTML = <option value='foo'>Foo</option>;
I have an options menu in an Activity with three MenuItems create select delete
I have setup my default android Preferences with the necessary options. The prime reason
I have some options for pricing using radio buttons. When a user selects the
I am still learning socket programming (using Perl) but I have both options (
well, I have my Android app that have 4 main options. For that I
I have one requirement in which User will have options to select languages for
For my app, I have a fairly complex set of configuration options that user
I have an object, Activity . On Activity, the user can select a Frequency
I have two options select photo and take photo - I have my select

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.