gpt4 book ai didi

java - 我的语法有什么问题?

转载 作者:太空宇宙 更新时间:2023-11-03 12:23:20 25 4
gpt4 key购买 nike

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); {

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

;
}}

最佳答案

这个:

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

(在内部类的内容之前没有分号;并且,在函数调用结束时有右括号)。

关于java - 我的语法有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8867225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com