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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:03:39+00:00 2026-05-24T22:03:39+00:00

So I’m not sure if I’m just blind to the problem or what’s going

  • 0

So I’m not sure if I’m just blind to the problem or what’s going on. From everything I have checked this should be working just fine. I’m guessing there is something tiny in here that I am not noticing and I am hoping someone else will catch it because I’m not seeing it. Basically the first class has spinners and it takes input and saves them all, loading up the old information and adding the new to them. Then it does a calculation to give me the new double for one of them. The second class is what displays them. For some reason it is constantly displaying the onbasePerc as 0.000. The calculation that it should be doing should be giving me a number and I am not sure why it is not.

Here is the input class

public class AddGameBR extends Activity{

private static final String[] stealAttempt = {"0","1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15","16","17","18","19","20"};
private static final String[] stolenBase = {"0","1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15","16","17","18","19","20"};
private static final String[] caughtSteal = {"0","1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15","16","17","18","19","20"};
private static final String[] runs = {"0","1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15","16","17","18","19","20"};

double stolenPerc=0;
int sa=0, sb=0, caught=0, run=0;

double ostolenPerc=0;
int osa=0, osb=0, ocaught=0, orun=0;

double nstolenPerc=0;
int nsa=0, nsb=0, ncaught=0, nrun=0;

public static final String PREFS_NAME = "GameSaved";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addgamebr);

    oldStats();

    //Baserunning Stats

    final Spinner spin16 = (Spinner) findViewById(R.id.spin16);
    ArrayAdapter<String> spinn16 = new
        ArrayAdapter<String>(this, R.layout.spinner_entry, stealAttempt);
    spinn16.setDropDownViewResource(R.layout.spinner_entry);
    spin16.setAdapter(spinn16);

    final Spinner spin17 = (Spinner) findViewById(R.id.spin17);
    ArrayAdapter<String> spinn17 = new
        ArrayAdapter<String>(this, R.layout.spinner_entry, stolenBase);
    spinn17.setDropDownViewResource(R.layout.spinner_entry);
    spin17.setAdapter(spinn17);

    final Spinner spin18 = (Spinner) findViewById(R.id.spin18);
    ArrayAdapter<String> spinn18 = new
        ArrayAdapter<String>(this, R.layout.spinner_entry, caughtSteal);
    spinn18.setDropDownViewResource(R.layout.spinner_entry);
    spin18.setAdapter(spinn18);

    final Spinner spin19 = (Spinner) findViewById(R.id.spin19);
    ArrayAdapter<String> spinn19 = new
        ArrayAdapter<String>(this, R.layout.spinner_entry, runs);
    spinn19.setDropDownViewResource(R.layout.spinner_entry);
    spin19.setAdapter(spinn19);

    Button save = (Button) findViewById(R.id.save);
    save.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View calculate)
        {
             //Running


            sa = Integer.parseInt((String) spin16.getSelectedItem());
            sb = Integer.parseInt((String) spin17.getSelectedItem());
            caught = Integer.parseInt((String) spin18.getSelectedItem());
            run = Integer.parseInt((String) spin19.getSelectedItem());

            nsa = sa + osa;
            nsb = sb + osb;
            ncaught = caught + ocaught;
            nrun = run + orun;

            if(nsa==0)
                nstolenPerc=0;
            else
                nstolenPerc = nsb / nsa;

            if(sa<sb){
                AlertDialog.Builder builder = new AlertDialog.Builder(AddGameBR.this);
                builder.setMessage("You have more Stolen Bases than Steal Attempts. Please fix and then resubmit.")
                       .setCancelable(false)
                       .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                           }
                       });
                AlertDialog alert = builder.create();
                builder.show();
            }
            else{

                AlertDialog.Builder builder = new AlertDialog.Builder(AddGameBR.this);
                builder.setMessage("Are you sure these stats are correct? \n\nAfter submitting they are final.")
                       .setCancelable(false)
                       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int id) {


                               SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_WORLD_READABLE);
                                SharedPreferences.Editor editor = settings.edit();
                                saveGame(editor);
                                editor.commit();

                               Intent i = new Intent(AddGameBR.this, ViewBR.class);
                                startActivity(i);
                                finish();
                           }
                       })
                       .setNegativeButton("No", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                           }
                       });
                AlertDialog alert = builder.create();
                builder.show();
            }
        }
    });

}

public void saveGame(SharedPreferences.Editor map){
    if (map == null) {          
        return;
    }
    //Baserunning
            map.putInt("stealattempts", nsa);
            map.putInt("stolenbases", nsb);
            map.putInt("caughtstealing", ncaught);
            map.putInt("run", nrun);
            map.putString("stealPercentage", Double.toString(nstolenPerc));
}

public void oldStats(){
     SharedPreferences saved = this.getSharedPreferences(PREFS_NAME, MODE_WORLD_READABLE);
    //Baserunning
        osa = saved.getInt("stealattempts", 0);
        osb = saved.getInt("stolenbases", 0);
        ocaught = saved.getInt("caughtstealing", 0);
        orun = saved.getInt("run", run);
        ostolenPerc = Double.parseDouble(saved.getString("stealPercentage", "0"));
}

}

This is the viewing class

public class ViewBR extends Activity{
public static final String PREFS_NAME = "GameSaved";

double stolenPerc=0;
int sa=0, sb=0, caught=0, run=0;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.viewbr);

// this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    oldStats();

    final DecimalFormat formatter = new DecimalFormat("0.000");

    if(sa==0)
        stolenPerc=0;
    else
        stolenPerc = sb / sa;

  //Base Running

    TextView stealattempts = (TextView)findViewById(R.id.stealattempts);
    stealattempts.setText("Steal Attempts: " + sa);

    TextView stolenbases = (TextView)findViewById(R.id.stolenbases);
    stolenbases.setText("Stolen Bases: " + sb);

    TextView caughtstealing = (TextView)findViewById(R.id.caughtstealing);
    caughtstealing.setText("Caught Stealing: " + caught);

    TextView runs = (TextView)findViewById(R.id.runs);
    runs.setText("Runs: " + run);

    TextView stolenpercentage = (TextView)findViewById(R.id.stolenpercentage);
    stolenpercentage.setText("Stolen Base Percentage: " + formatter.format(stolenPerc) + "%");

    Button copy = (Button) findViewById(R.id.copy_btn);
    copy.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View copy)
        {
            ClipboardManager clipboard = 
                      (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 

                 clipboard.setText("Base Running Stats:" +
                        "\nSteal Attempts: " + sa+
                        "\nStolen Bases: " + sb +
                        "\nCaught Stealing: " + caught +
                        "\nRuns: " + run +
                        "\nStolen Base Percentage: " + formatter.format(stolenPerc) + "%");
                 Toast.makeText(ViewBR.this, "Copied To Clipboard", 1).show();
        }
    });


}

public void oldStats(){
     SharedPreferences saved = this.getSharedPreferences(PREFS_NAME, MODE_WORLD_READABLE);

    //Baserunning
        sa = saved.getInt("stealattempts", 0);
        sb = saved.getInt("stolenbases", 0);
        caught = saved.getInt("caughtstealing", 0);
        run = saved.getInt("run", run);
        stolenPerc = Double.parseDouble(saved.getString("stealPercentage", "0"));
}

}

Any help would be appreciated. It’s probably going to be something so simple I am going to end up smacking myself in the face. Anyways take care. (Also when I am inputting it all I am not submitting it with sa as zero normally I am trying sa as 4 and sb as 2 which should be .500.

  • 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-24T22:03:39+00:00Added an answer on May 24, 2026 at 10:03 pm

    Have you debugged to step through teh codez and find out exactly what the values are before the problem method returns a bad value? Also – I may be off here but integer division will return an integer (your expected value is .5, it will be 0 instead). See this question.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from
Does anyone know how can I replace this 2 symbol below from the string

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.