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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:03:07+00:00 2026-06-07T05:03:07+00:00

Well… here’s a problem it looks like I’m not the first to experience looking

  • 0

Well… here’s a problem it looks like I’m not the first to experience looking through other questions, however I can’t find one that’s Android-specific (others are C++ or straight java with different scenarios).

I have a calculator that determines your fuel mileage needs with given user inputs. The thing I’m adding now is a “burnoff” aspect where you can calculate the weight lost over the course of the race. Before adding the weight/burnoff element, everything worked fine.

Now, everything calculates normally except the weight on the first click.

On the second click (and subsequent clicks) it calculates properly. I suspect it has something to do with the switch statement and its location, but I could be wrong…. and even if I’m not, I’m not sure how to change it.

Looking for help on getting it all functioning properly on the first click. Thanks!

EDIT: The non-exception Toast text I put in as a debugger to determine if it was a math issue or what in the code. It pops up with “0.0” on the first click, then either “6.2” or “6.6” on subsequent clicks.


    package com.tomcat.performance;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Gravity;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.RadioButton;
    import android.widget.RadioGroup;
    import android.widget.RadioGroup.OnCheckedChangeListener;
    import android.widget.TextView;
    import android.widget.Toast;


    public class Fuelsimple extends Activity implements OnCheckedChangeListener{

double fuelweight;

public void onCheckedChanged(RadioGroup group, int checkedId) {
    // TODO Auto-generated method stub
    switch (checkedId){
    case R.id.rbMethanol:
        fuelweight = 6.6;
        break;
    case R.id.rbGasoline:
        fuelweight = 6.2;
        break;}
}

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.fuelsimple);

RadioGroup rgFuelType = ((RadioGroup) findViewById (R.id.rgFuelType));
rgFuelType.setOnCheckedChangeListener(this);
RadioButton rbMethanol = ((RadioButton) findViewById(R.id.rbMethanol));
RadioButton rbGasoline = ((RadioButton) findViewById(R.id.rbGasoline));

Button gen = ((Button) findViewById(R.id.submit));  
gen.setOnClickListener(new View.OnClickListener() { 



        public void onClick(View v) {
    // TODO Auto-generated method stub      

            EditText fuelUsed, pracLaps, featureLaps;

            pracLaps = ((EditText) findViewById(R.id.pracLaps));
            fuelUsed = ((EditText) findViewById(R.id.fuelUsed));
            featureLaps = ((EditText) findViewById(R.id.featureLaps));
            TextView textLPGValue, textFuelNeededValue, textBurnoffValue;
            try{
            double pracLapsVar = Double.parseDouble(pracLaps.getText().toString());
            double fuelUsedVar = Double.parseDouble(fuelUsed.getText().toString());
            double featureLapsVar = Double.parseDouble(featureLaps.getText().toString());

            double efficiency = (pracLapsVar / fuelUsedVar);
            double fuelNeeded = (featureLapsVar / efficiency);
            double burnoff = (1.05 * (fuelNeeded * fuelweight));

            Toast andJelly = Toast.makeText(Fuelsimple.this, String.valueOf(fuelweight), Toast.LENGTH_LONG);
            andJelly.show();


            textLPGValue = ((TextView) findViewById(R.id.textLPGValue));
            textFuelNeededValue = ((TextView) findViewById(R.id.textFuelNeededValue));
            textBurnoffValue = ((TextView) findViewById(R.id.textBurnoffValue));

            textLPGValue.setText(String.valueOf(String.format("%.3f", efficiency)) + " laps per gallon");
            textFuelNeededValue.setText(String.valueOf(String.format("%.3f", fuelNeeded)) + " gallons");
            textBurnoffValue.setText(String.valueOf(String.format("%.2f", burnoff)) + " pounds");
            } catch (NumberFormatException e) {Toast andEggs = Toast.makeText(Fuelsimple.this, "Please complete all fields and enter your fuel & lap info in decimals or whole numbers.", Toast.LENGTH_LONG); andEggs.show();} 
            catch (NullPointerException n) {Toast andEggs = Toast.makeText(Fuelsimple.this, "Please enter ALL lap and fuel data.", Toast.LENGTH_LONG);
            andEggs.show();}
        }}
);      
}
    public void onClick(View v) {
    }
    }
  • 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-06-07T05:03:10+00:00Added an answer on June 7, 2026 at 5:03 am

    As far as I can tell, your variable fuelWeight is never initialized until a radio button is pressed. The simplest way to fix this would be to call setChecked(true) on either rbmethanol or rbGasoline after setting the listener, maybe right below where you initialize those variables. Doing it after setting the listener is important, because you want the switch statement to be resolved. Right now, before you press a radio button, fuelWeight, as with all numeric primitive data types, will be initialized to 0. This is probably the reason your first calculations are wrong.

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

Sidebar

Related Questions

Well im here because i have a problem. i have code that was created
Well, I got problem here with opengl ES stuff (just started to learn about
Well, this must be a silly one. Here below is a can-not-be-simpler code in
Well, this is my first post here and really enjoying the site. I have
Well the problem is that I was using code like this: new Date().toJSON().slice(0, 10)
Well, my website can not redirect to https://www.facebook.com/QuaFootSpa from http://quafootspa.com/ I have tried redirection
well i have a configuration like this in the components part of my config
Well it's not realy causing any errors. Anyways i'm sending ajax request and getting
Well normally I am quite good at figuring and researching problems without guidance however
well i have used an html file like these in iframe <iframe src=sample.html></iframe> is

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.