3

Eclipse is giving me many errors for one specific line of code says:

Multiple markers at this line

- Syntax error, insert ")" to complete 
 ConstructorDeclaration
- Syntax error, insert "}" to complete ClassBody
- Syntax error, insert ";" to complete 
 ConstructorDeclaration
- Syntax error, insert ";" to complete Statement
- Syntax error, insert ")" to complete 
 MethodInvocation

The line is:

setOnClickListener(new View.OnClickListener(); {

and on a different line i get errors

Multiple markers at this line

- Syntax error on token ")", delete 
 this token
- Syntax error on token "(", ; expected

for line: public void onClick(View v); {

Heres activity2.java:

package android.app;
import android.app.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class activity2 extends Activity{
 /** Called when the activity is first created. */
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main2);
 Button next = (Button) findViewById(R.id.Back);
 next.setOnClickListener(new View.OnClickListener() {
 public void onClick(View view) {
 Intent intent = new Intent();
 setResult(RESULT_OK, intent);
 finish();
 }
 Button sound = (Button) findViewById(R.id.sound);
 setOnClickListener(new View.OnClickListener(); {
 @Override
 public void onClick(View v); {
 MediaPlayer mp = MediaPlayer.create(TestSonido.this, R.raw.whippingsound); 
 mp.start();
 }
 }
 ;
 ;
}}
Mysticial
473k46 gold badges343 silver badges337 bronze badges
asked Jan 15, 2012 at 2:53
1
  • 1
    What are you trying to do there? Perhaps you want to get rid of the semicolon by changing View.OnClickListener(); { to View.OnClickListener() { You're also missing the closing parenthesis. You need to count opening and closing parenthesis to be sure that they match. Commented Jan 15, 2012 at 2:56

2 Answers 2

5

This:

 setOnClickListener(new View.OnClickListener(); {
 @Override
 public void onClick(View v); {
 MediaPlayer mp = MediaPlayer.create(TestSonido.this, R.raw.whippingsound); 
 mp.start();
 }
 }

should be this:

 setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 MediaPlayer mp = MediaPlayer.create(TestSonido.this, R.raw.whippingsound); 
 mp.start();
 }
 })

(no semicolon before the contents of the inner class; and, yes right-parenthesis at end of function call).

Matt Ball
361k102 gold badges655 silver badges725 bronze badges
answered Jan 15, 2012 at 2:58
Sign up to request clarification or add additional context in comments.

3 Comments

You will need a semicolon to end the statement.
@I82Much: There is one. (That semicolon is on a separate line in the original code, so I left it there.)
setOnClickListener(new View.OnClickListener() { is still requesting semi colon?? @ruakh
2
setOnClickListener(new View.OnClickListener(); {

=>

setOnClickListener(new View.OnClickListener() {
ffriend
28.7k14 gold badges93 silver badges137 bronze badges
answered Jan 15, 2012 at 2:56

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.