Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy isn't this switch case firing?
    primarykey
    data
    text
    <p>I have a whole line of switch cases tied to oncheckboxclickeds that I'm using to total up a number. </p> <p>Every case in the line works beautifully, except the last one, which seems not to do anything at ALL, and I can't figure out why.</p> <p>This works just fine, right till the end:</p> <pre><code>package com.example.blazingboltcalculator; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.CheckBox; import android.widget.TextView; public class MainActivity extends Activity { int attack=11; int damage=3; int flankAttack; int pbs; int justice; int destruction; int bane; int DF; int GMW; int heroism; int deadly; int attackTotal; int damageTotal; String flames=""; String baneDice=""; String keen=""; String diceTotal; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } public void onCheckboxClicked(View v) { // Is the view now checked? boolean checked = ((CheckBox) v).isChecked(); // Check which checkbox was clicked switch(v.getId()) { case R.id.checkBox1: if (checked) { flankAttack=2; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); } else { flankAttack=0; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); } break; case R.id.checkBox2: if (checked) { pbs=1; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); } else { pbs=0; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); } break; case R.id.checkBox3: if (checked) { justice=2; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); } else { justice=0; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); } break; case R.id.checkBox4: if (checked) { destruction=4; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); } else { destruction=0; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); } break; case R.id.checkBox5: if (checked) { bane=2; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; baneDice="+2d6"; diceTotal="1d8"+baneDice+flames+keen; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); TextView textView3 = (TextView) findViewById(R.id.textView6); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); textView3.setText(diceTotal); } else { bane=0; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; baneDice=""; diceTotal="1d8"+baneDice+flames+keen; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); TextView textView3 = (TextView) findViewById(R.id.textView6); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); textView3.setText(diceTotal); } break; case R.id.checkBox6: if (checked) { DF=3; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); } else { DF=0; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); } break; case R.id.checkBox7: if (checked) { flames="+1d6 fire"; diceTotal="1d8"+baneDice+flames+keen; TextView textView3 = (TextView) findViewById(R.id.textView6); textView3.setText(diceTotal); } else { flames=""; diceTotal="1d8"+baneDice+flames+keen; TextView textView3 = (TextView) findViewById(R.id.textView6); textView3.setText(diceTotal); } break; case R.id.checkBox8: if (checked) { GMW=1; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); } else { GMW=0; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); } break; case R.id.checkBox9: if (checked) { heroism=2; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); } else { heroism=0; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); } break; case R.id.checkBox10: if (checked) { keen="+19-20 crit"; diceTotal="1d8"+baneDice+flames+keen; TextView textView3 = (TextView) findViewById(R.id.textView6); textView3.setText(diceTotal); } else { keen=""; diceTotal="1d8"+baneDice+flames+keen; TextView textView3 = (TextView) findViewById(R.id.textView6); textView3.setText(diceTotal); } break; case R.id.checkBox11: if (checked) { deadly=2; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); } else { deadly=0; attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly; damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly; TextView textView = (TextView) findViewById(R.id.textView2); TextView textView2 = (TextView) findViewById(R.id.textView4); textView.setText(Integer.toString(attackTotal)); textView2.setText(Integer.toString(damageTotal)); } } } </code></pre> <p>}</p> <p>I'm kinda new to programming, does anyone have any idea what might be gumming up the works? The whole mess works perfectly aside from that very last Case.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload