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

  • Home
  • SEARCH
  • 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 6143159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:29:10+00:00 2026-05-23T18:29:10+00:00

So far I have been able to successfully pass a string using this method,

  • 0

So far I have been able to successfully pass a string using this method, however it seems to not be working when I try to pass an integer.

Class that is setting the integer has the following:

My Helper

    public int getHoles() {
    return setHoles;
}

My Button

case R.id.buttonSetHoles:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        final CharSequence[] items = {"18", "9"};
        builder.setTitle("Set Holes");
        builder.setItems(items, new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialogInterface, int item) {
                Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
                if (items[item] == "9"){
                    int setHoles = 9;
                }
                else if (items[item] == "18"){
                    int setHoles = 18;
                }
                return;
            }
        });
        builder.create().show();
        return;

Class that needs the data

        public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    String name1 = EasyPar.helper.getNames(); <--- works fine for this one
    int setHoles = EasyPar.helper.getHoles();
}

Whenever I try to use the value, it just comes up with nothing. If i try to:

textHoleNumber.setText(String.valueOf(setHoles));

it just displays 0

the only way I can get it to work is if i just set the value upfront as setHoles = 18; or so.

I tried to move the “helper” to the end of the class but that didnt work. I am thinking that the My Button is not correctly setting the setHoles value or I am not correctly passing the value outside of the “case R.id.buttonLetsGo” (if i put setHoles = 10; inside of public int getHoles() {
return setHoles;
} then it works no problem so its definitely calling that getHoles.

If theres any more data i can provide please let me know!

Thanks in advance!

  • 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-23T18:29:11+00:00Added an answer on May 23, 2026 at 6:29 pm

    Your problem seems to be a scoping problem:

                if (items[item] == "9"){
                    int setHoles = 9;
                }
                else if (items[item] == "18"){
                    int setHoles = 18;
                }
    

    You’re declaring new “setHoles” integers here, and they only exist for one line. Any other variable named “setHoles” from elsewhere in your code is being hidden by these new ones. (Your compiler should be giving you a warning about this, too.)

    I hope that helps!

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

Sidebar

Related Questions

I am pretty new to GraniteDS..So far I have been able to successfully configure
I have been using Eclipse for R and C++. So far I have not
I'm trying to install bcrypt-ruby on Windows Vista. So far, I have been able
Thus far you guys have been wildly helpful with me getting this little ditty
This has / may have been asked before, but, as far as I remember,
I have an asterisk-based PBX, and I have been able to successfully run an
I have successfully created a WS client that works correctly when NOT using authentication.
I'm trying to write a memory profiler and so far have been able to
I'm making an iphone only app, so far I have been able to share
So far I have been creating Web Portal but recently I had a request

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.