For some reason, when i check for the input of the spinner using an array with a switch statement it does this weird thing. If i use any sort of "if-statement" "for-loop" any thing of that nature, it wont through an error, just when I open the virtual device it will say app has stopped working. When I remove the if-statement or for-loop it will work fine. The reason I need to use an if statement is because i want to check if the checkbox is checked.
Heres my code:
package com.example.gcfcalculator; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.Spinner; import android.widget.TextView; public class MainActivity extends Activity implements OnItemSelectedListener { Spinner spinner; String[] paths = {"Rectangle", "Circle", "Triangle"}; Button equals; TextView parm1, parm2; EditText value1, value2; CheckBox checkArea, checkPerm; Boolean checkedArea = false, checkedPerm = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_item, paths); spinner = (Spinner) findViewById(R.id.spinner); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(this); } @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { int position = spinner.getSelectedItemPosition(); switch(position){ case 0: //Rectangle //Problem happens here!!! if(checkArea.isChecked()){ System.out.println("Area is checked"); } break; case 1: //Square break; case 2: //Triangle break; } } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }