Eclipse为一行特定代码提供了许多错误:
此行有多个标记
- 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
该行是:
setOnClickListener(new View.OnClickListener(); {
在不同的一行我得到错误
此行有多个标记
- 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();
}
}
;
;
}}
答案 0 :(得分:5)
此:
setOnClickListener(new View.OnClickListener(); {
@Override
public void onClick(View v); {
MediaPlayer mp = MediaPlayer.create(TestSonido.this, R.raw.whippingsound);
mp.start();
}
}
应该是这样的:
setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MediaPlayer mp = MediaPlayer.create(TestSonido.this, R.raw.whippingsound);
mp.start();
}
})
(在内部类的内容之前没有分号;并且,在函数调用结束时是的是右括号)。
答案 1 :(得分:2)
setOnClickListener(new View.OnClickListener(); {
=>
setOnClickListener(new View.OnClickListener() {