简体   繁体   中英

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

    ;
}}

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

setOnClickListener(new View.OnClickListener(); {

=>

setOnClickListener(new View.OnClickListener() {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM