[Solved] Eclipse:error missing (,} [closed]


The error messages are very descriptive. Check file MainActivity.java, line 65 and fix it. Similar for line 86.

Anyway, these are the errors:

Syntax error on token “)”, { expected MainActivity.java /CalculatorVamalV2/src/com/elitiv/calculatorvamalv2 line 65 Java Problem

You missed a close brace } in the inner class definition:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

    TextView Year = (TextView)findViewById(R.id.Year);
    TextView Capacity = (TextView)findViewById(R.id.Capacity);
    editYear = (EditText)findViewById(R.id.editYear);
    editCapacity = (EditText)findViewById(R.id.editCapacity);
    Result = (EditText)findViewById(R.id.Result);
    Button   calc =(Button)findViewById(R.id.calc);
    final RadioButton RadioD = (RadioButton)findViewById(R.id.radioD);
    final RadioButton RadioB = (RadioButton)findViewById(R.id.radioB);

    calc.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            double editYear = editYear.getText().toString();
            double editCapacity = editYear.getText().toString();

            if(RadioB.isChecked()){
                switch(editYear){
                case 2014:
                    if(editCapacity >0 && NCapacity <1000){
                        Result = editCapacity*0.57;

                }
                    if(editCapacity >1000 && editCapacity <1500){
                        Result = editCapacity*0.67;

                }
                    if(editCapacity >1501 && editCapacity <2000){
                        Result = editCapacity*1.00;

                }
                break;
            }

        }
                } // <-- add this here
    });
}

Syntax error, insert “}” to complete ClassBody MainActivity.java /CalculatorVamalV2/src/com/elitiv/calculatorvamalv2 line 86 Java Problem

You don’t have an anonymous class here, so there’s no need to have );:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

Besides this, you have an additional brace } at the end of the definition of your class.


How to avoid these problems?

Indent your code. Since you’re using eclipse and android development studio (based on Eclipse), you have this shortcut to let the IDE auto format the code automatically for you: Ctrl + Shift + F.

solved Eclipse:error missing (,} [closed]