Tadas
Tadas

Reputation: 176

Why does my braces shows error?

enter image description here

enter image description here

Hello everyone. Today i started writting a code so i could open second activity while i am pressing on the button. And i am keep getting the "{}" brace errors. I also created manifest "android:name=".activity2">" But i can't find the way how should i fix my braces to stop showing error? I uplauded some pictures so you could see a bit better what's the problem. Maybe there is way easier way to open the second activity with the button? Any tips to fix the problem? Thank you :)

public class MainActivity extends Activity {

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

    Button imeageTextBtn = (Button) findViewById(R.id.imeageTextBtn);
    assert imeageTextBtn != null;
    imeageTextBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(v.getContext(), activity2.class);
            startActivityForResult(intent, 0);
        }
    }

}

Upvotes: 0

Views: 116

Answers (2)

Debosmit Ray
Debosmit Ray

Reputation: 5403

After imeageTextBtn.setOnclick...., you need to add a ); after the }

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

    Button imeageTextBtn = (Button) findViewById(R.id.imeageTextBtn);
    assert imeageTextBtn != null;
    imeageTextBtn.setOnClickListener(
        new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(v.getContext(), activity2.class);
                startActivityForResult(intent, 0);
            }
        }
    );

}

Upvotes: 2

Ali Seyedi
Ali Seyedi

Reputation: 1817

You're calling the setOnClickListener method. so it needs a closing ) and a semicolon.

imeageTextBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = new Intent(v.getContext(), activity2.class);
        startActivityForResult(intent, 0);
    }
});

Upvotes: 4

Related Questions