1

I don't understand the concept with curly braces. It's getting annoying. I have 4 open and 4 closing curly braces. Shouldn't this negate any errors with them then?

package net.androidbootcamp.starconstellations;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button b=(Button)findViewById(R.id.button1);
    b.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
    startActivity(new Intent(MainActivity.this, Pegasuss.class));
}
    }
}
} 
2
  • Your parentheses from b.setOnClickListener( are never closed.
    – khelwood
    Commented Nov 23, 2014 at 0:37
  • Compliments on the question title. Nothing quite compares to the SO Mechanical Turk to look over your curly braces :)
    – Andreas
    Commented Nov 23, 2014 at 3:07

3 Answers 3

1

If you're using eclipse, press Ctrl+Shift+F to auto-indent, and then your code will be very easy to read and you'll be able to follow the blocks created by the curly braces.

It's always a good idea to keep the code correctly indented.

1
  • Actually the default is Ctrl+I ;)
    – Andreas
    Commented Nov 23, 2014 at 3:03
1

Your on click listener doesn't have a closing normal bracket ')':

b.setOnClickListener(new OnClickListener(){
    ....
});
0
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button b=(Button)findViewById(R.id.button1);
        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                startActivity(new Intent(MainActivity.this, Pegasuss.class));
            }
        });
    }

}

This code should do the trick. The problem is you need to close the parenthesis and the line b.setOnClickListener ( Your on click listener );. I would also recommend formatting your code better in the future as it will make it easier to deal with parenthesis and bracket issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.