I\'m getting the red squiggle under a parenthesis this time, telling me \"insert \"EnumBody\" to complete EnumDeclaration\"
It is happening on the last line of this cod
Replace your activity code with these lines of code and try compiling again:
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button2).setOnClickListener(new handleButton2());
findViewById(R.id.button3).setOnClickListener(new handleButton3());
findViewById(R.id.button4).setOnClickListener(new handleButton4());
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.work_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
if (position == 1){
Intent intent = new Intent(Main.this, Upperbody.class);
Main.this.startActivity(intent);
}
if (position == 2){
Intent intent = new Intent(Main.this, Settings.class);
Main.this.startActivity(intent);
}
if (position == 3){
Intent intent = new Intent(Main.this, Progress.class);
Main.this.startActivity(intent);
}
}
} );
}
class handleButton2 implements OnClickListener {
public void onClick(View v) {
Intent intent = new Intent(Main.this, Benchmark.class);
startActivity(intent);
}
}
class handleButton3 implements OnClickListener {
public void onClick(View v) {
Intent intent = new Intent(Main.this, Progress.class);
startActivity(intent);
}
}
class handleButton4 implements OnClickListener {
public void onClick(View v) {
Intent intent = new Intent(Main.this, Settings.class);
startActivity(intent);
}
}
}
Is this the actual code? Could it be the additional "@" character at the end of class handleButton4?
class handleButton4 implements OnClickListener {
public void onClick(View v) {
Intent intent = new Intent(Main.this, Settings.class);
startActivity(intent); } }@ // <------- this
It seems to me that the method onCreate has been closed to early, the spinner.setOnItemSelectedListener should be in that and the defined inner clsses outside of the method. The spinner.setOnItemSelectedListener just floats around in the middle of the class, maybe it should be in the onCreate method. (which might be valid syntax, but I'm not sure if that's the thing what you want to achieve)
The statement might be handled like a initialization Block in Java, even without parenthesis. (but I'm not 100% sure) See: http://jpz-log.info/archives/2009/03/25/initialization-blocks-in-java/