Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with my syntax?

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();
                }
            }
            ;

    ;
}}
like image 632
user1148715 Avatar asked Dec 02 '25 13:12

user1148715


1 Answers

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).

like image 169
ruakh Avatar answered Dec 04 '25 02:12

ruakh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!