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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:18:06+00:00 2026-06-13T21:18:06+00:00

I have code that was working earlier and now seems to be throwing some

  • 0

I have code that was working earlier and now seems to be throwing some errors with regard to a case statement I have for a button event. The case structure looks at which button is clicked and does something and it’s the second case that is aggravating me. The error in Eclipse on the line that says case R.id.button2: is telling me “syntax error on token “case”, @ expected” and on the line below it (Intent), it is saying “syntax error, insert “;” to complete assert statement”. However, it seems like the error messages keep changing. Earlier, Eclipse was nagging me to put a “;” instead of a @ and I’m not sure why since the code was fine earlier. I’ve tried putting “;” after the colon in the second case line and still throws an error. I’m not sure why it’s happening all of a sudden or why the error messages keep changing, despite typing what it wants (which usually fixes things in Eclipse.) Did I miss something in my case structure? Thanks.

Here is my code (posting in full):

import java.text.DecimalFormat;
import java.text.NumberFormat;

import android.R.integer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Button;
import android.widget.TextView;
import android.view.View;


public class MainActivity extends Activity {
EditText mile,diesel;
Button button1, button2;
TextView tv, tv2, tv3;
private double x, y, z, costper, gallon, litres, ophours, ophour, drive, stopdrive;
CheckBox checkBox1, checkBox2, checkBox3, checkBox4;
NumberFormat format  = NumberFormat.getCurrencyInstance();
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mile= (EditText) findViewById(R.id.mile);
    checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
    checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
    checkBox3 = (CheckBox) findViewById(R.id.checkBox3);
    checkBox4 = (CheckBox) findViewById(R.id.checkBox4);         
    button1 = (Button) findViewById(R.id.button1);
    button2 = (Button) findViewById(R.id.button2);
    button1.setOnClickListener(onClickListener);
    button2.setOnClickListener(onClickListener);
    tv = (TextView) findViewById(R.id.cost);
    tv2 = (TextView) findViewById(R.id.cpm);
    tv3 = (TextView) findViewById(R.id.gallons);
    diesel= (EditText) findViewById(R.id.diesel);
         }

private OnClickListener onClickListener = new OnClickListener() {
   @Override
   public void onClick(final View v) {
       switch(v.getId()){
         case R.id.button1:
            x=Double.parseDouble(mile.getText().toString());
            y=Double.parseDouble(diesel.getText().toString());
            ophour = x/55;
            ophours = 0;
            if (ophour>10){
                drive = ophour/10;
                if (drive>1) {
                    stopdrive = drive-1;
                    ophour = ophour + 10;
                    if (stopdrive>1);
                    ophour = ophour + (10*stopdrive);
                    if (stopdrive<1);
                    ophour = ophour + 10;
                }
                                    }
                ophours = ((x/55)*10);
            }
            if (checkBox2.isChecked()) {
                 x=x*2;
             }
            if (checkBox1.isChecked()) {
                x=x*0.62137;
            }
            gallon = x/5.5;
            if (checkBox4.isChecked()) {
                gallon = gallon + (ophour*1.1);
            }
            if (checkBox3.isChecked()) {
                litres = gallon*3.785;
                tv3.setText(new DecimalFormat("####.##").format(litres)+"L");
            }
            z=(gallon*y)+(x*0.655);
            costper=z/x;
            tv.setText(format.format(z));
            tv2.setText(format.format(costper)+"/mile"); 
            tv3.setText(new DecimalFormat("####.##").format(gallon)+"gal.");
         break;
         case R.id.button2:
            Intent browserIntent = 
            new Intent(Intent.ACTION_VIEW, Url.parse("http://www.google.com"));
                                 startActivity(browserIntent);   
         break;
       }
   ;};}         
  • 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-13T21:18:08+00:00Added an answer on June 13, 2026 at 9:18 pm

    Your {}s are simply mismatched. This is an excellent example of why it is important to properly format your code, including indentation.

    I’ve taken the time to do this for you, though you can do it in Eclipse by using Control+Shift+F:

    import java.text.DecimalFormat;
    import java.text.NumberFormat;
    
    import android.R.integer;
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.Intent;
    import android.widget.CheckBox;
    import android.widget.EditText;
    import android.widget.Button;
    import android.widget.TextView;
    import android.view.View;
    
    public class MainActivity extends Activity {
        EditText mile,diesel;
        Button button1, button2;
        TextView tv, tv2, tv3;
        private double x, y, z, costper, gallon, litres, ophours, ophour, drive, stopdrive;
        CheckBox checkBox1, checkBox2, checkBox3, checkBox4;
        NumberFormat format  = NumberFormat.getCurrencyInstance();
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mile= (EditText) findViewById(R.id.mile);
            checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
            checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
            checkBox3 = (CheckBox) findViewById(R.id.checkBox3);
            checkBox4 = (CheckBox) findViewById(R.id.checkBox4);         
            button1 = (Button) findViewById(R.id.button1);
            button2 = (Button) findViewById(R.id.button2);
            button1.setOnClickListener(onClickListener);
            button2.setOnClickListener(onClickListener);
            tv = (TextView) findViewById(R.id.cost);
            tv2 = (TextView) findViewById(R.id.cpm);
            tv3 = (TextView) findViewById(R.id.gallons);
            diesel= (EditText) findViewById(R.id.diesel);
        }
    
        private OnClickListener onClickListener = new OnClickListener() {
            @Override
            public void onClick(final View v) {
                switch(v.getId()){
                    case R.id.button1:
                        x=Double.parseDouble(mile.getText().toString());
                        y=Double.parseDouble(diesel.getText().toString());
                        ophour = x/55;
                        ophours = 0;
                        if (ophour>10){
                            drive = ophour/10;
                            if (drive>1) {
                                stopdrive = drive-1;
                                ophour = ophour + 10;
                                if (stopdrive>1); // This IF statement will ALWAYS execute; remove the ";"
                                    ophour = ophour + (10*stopdrive);
                                if (stopdrive<1); // This IF statement will ALWAYS execute; remove the ";"
                                    ophour = ophour + 10;
                            }
                        }
                        ophours = ((x/55)*10);
                        } // This should not be here
                        if (checkBox2.isChecked()) {
                            x=x*2;
                        }
                        if (checkBox1.isChecked()) {
                            x=x*0.62137;
                        }
                        gallon = x/5.5;
                        if (checkBox4.isChecked()) {
                            gallon = gallon + (ophour*1.1);
                        }
                        if (checkBox3.isChecked()) {
                            litres = gallon*3.785;
                            tv3.setText(new DecimalFormat("####.##").format(litres)+"L");
                        }
                        z=(gallon*y)+(x*0.655);
                        costper=z/x;
                        tv.setText(format.format(z));
                        tv2.setText(format.format(costper)+"/mile"); 
                        tv3.setText(new DecimalFormat("####.##").format(gallon)+"gal.");
                        break;
                    case R.id.button2:
                        Intent browserIntent = 
                        new Intent(Intent.ACTION_VIEW, Url.parse("http://www.google.com"));
                        startActivity(browserIntent);   
                        break;
                // There should be a "}" here.
            };
        };
    }
    

    Now, I’ve added 4 comments in here to show you issues with the code (though only 2 are related to this issue).

    • On about Line 62, there is a } that should not be there.
    • On about Line 88, there is no }, and there should be. (End of switch.)
    • (Unrelated) On about Line 55, you have an if statement which will always execute due to ;.
    • (Unrelated) On about Line 57, you have an if statement which will always execute due to ;.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a memory matching game. I have some code that checks
I have some code I am working on that worked just fine until I
I have to modify some code in a application I am working on that
I have been working on some code, which I use git to manage. Earlier,
I have code that relies heavily on yaml for cross-language serialization and while working
I have a codeigniter code that is working on local Apache installation. But it
I have the following code that is working fine in jsfiddle - http://jsfiddle.net/darkajax/FHZBy/ I've
I am currently working on a project where I have code that looks like
I have a pretty typical bookmarklet code that's working perfectly for me in all
Hi I have been working on this code that creates a table with radio

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.