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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:33:00+00:00 2026-05-30T04:33:00+00:00

Why doesn’t my code switch at b.Equal recognize displayValue. All the other switches recognize

  • 0

Why doesn’t my code switch at b.Equal recognize “displayValue”. All the other switches recognize display. Is it because it’s a switch in a switch? Please let me know.

package rechee.cool;

import android.app.Activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

////////////////////////////////////////////////////////////

public class HelloAndroidActivity extends Activity {
  /** Called when the activity is first created. */

  // Here's display
  public EditText display;

  double total1=0.0;
  double total2=0.0;
  char theOperator;
  public String buttonText;
  public Button ButtonAdd, ButtonEqual, ButtonMultiply, ButtonDivide;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // display
    display= (EditText) findViewById(R.id.editText1);
  }

  public void getOperator(String btnText){
    theOperator = btnText.charAt(0);
    String display1= display.getText().toString();
    double displayValue= Double.parseDouble(display1);

    total1+=displayValue;
    display.setText("");
  }

  // All the switches recognize and use display... except for Equals
  public void onClick(View v) {
    switch(v.getId()){
      case R.id.bOne:
        display.append("1");
        break;
      case R.id.bTwo:
        display.append("2");
        break;
      case R.id.bThree:
        display.append("3");
        break;
      case R.id.bFour:
        display.append("4");
        break;
      case R.id.bFive:
        display.append("5");
        break;
      case R.id.bSix:
        display.append("6");
        break;
      case R.id.bSeven:
        display.append("7");
        break;
      case R.id.bEight:
        display.append("8");
        break;
      case R.id.bNine:
        display.append("9");
        break;
      case R.id.bZero:
        display.append("0");
        break;
      case R.id.bPoint:
        display.append(".");
        break;
      case R.id.bClear:
        display.setText("");
        break;
      case R.id.bAdd:
        buttonText="+";
        ButtonAdd= (Button)findViewById(R.id.bAdd);
        ButtonAdd.setText(buttonText);
        getOperator(buttonText);
        break;
      case R.id.bEqual:
        switch (theOperator){
          case '+':
          //Error right here. This switch doesn't recognize displayValue, 
          // but the other switches recognize display. Why?
          total2= total1 + displayValue;
        }
    }
  }
}
  • 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-30T04:33:02+00:00Added an answer on May 30, 2026 at 4:33 am

    This has got nothing to do with switch being inside another switch. The fact is that within the onClick() method, no such variable as displayValue even exists. The other switches recognize display, because display is a member variable of the class. They would not be able to recognize displayValue either, because displayValue is not a member variable of the class. In fact, the switch inside the switch would also be able to recognize display.

    I think you are confusing “display” with “displayValue”. They are different variables.

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

Sidebar

Related Questions

Why doesn't the file input element show up at all??? see code and screen
There doesn't seem to be a dictionary.AddRange() method. Does anyone know a better way
Why doesn't this piece of code swap images on mouse-over as intended?: <a href=#
Why doesn't the compiler automatically put break statements after each code block in the
Doesn't configuring WCF in code require more coupling with the model and service libraries?
Why doesn't this code work? I'am using FF. <head> <script type=text/javascript> document.getElementById(someID).onclick = function(){
Why doesn't this code print operator=? #include <iostream> using namespace std; class A{ public:
Doesn't work with other modules, but to give an example. I installed Text::CSV_XS with
Why doesn't Html.ActionLink work in the below code? This is a page in the
Why doesn't the following doesn't handle the exception that was rethrown? I tried all

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.