Android )预期或缺失
此代码中存在一个问题,因为在某个地方缺少此“')。光标显示设置按钮事件中缺少的组件。由于此错误,它不是生成的。缺少“'),它会终止编译器并生成失败。您永远不会关闭imagebutton4上的第一个onclicklistenerAndroid )预期或缺失,android,Android,此代码中存在一个问题,因为在某个地方缺少此“')。光标显示设置按钮事件中缺少的组件。由于此错误,它不是生成的。缺少“'),它会终止编译器并生成失败。您永远不会关闭imagebutton4上的第一个onclicklistener @TargetApi(Build.VERSION_CODES.LOLLIPOP) public class HomeActivity extends Activity { private static final String TAG = HomeActivity
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class HomeActivity extends Activity {
private static final String TAG = HomeActivity.class.getSimpleName();
private ImageButton imageButton;
private ImageButton imageButton2;
public ImageButton imageButton4;
public ImageButton imageButton5;
private ImageView imageView;
private ImageView imageView2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
imageButton = (ImageButton) findViewById(R.id.imageButton);
imageButton2 = (ImageButton) findViewById(R.id.imageButton2);
imageButton4 = (ImageButton) findViewById(R.id.imageButton4);
imageButton5 = (ImageButton) findViewById(R.id.imageButton5);
imageView = (ImageView) findViewById(R.id.imageView);
imageView2 = (ImageView) findViewById(R.id.imageView2);
//Single player button click event
imageButton4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),
MainActivity.class);
startActivity(i);
finish();
};},
//multi player game button event
imageButton5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),
MultiPlayer.class);
startActivity(i);
finish();
};}),
//Settings button event
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),
MusicActivity.class);
startActivity(i);
finish();
}
});
}}
最后一行应该是这样的
imageButton4.setOnClickListener**(**new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),
MainActivity.class);
startActivity(i);
finish();
};},
但我并没有真正理解你的onclick监听器背后的这些错误:
}}),
你需要关闭onclicklistener for ImageButton4(你不是在使用一个IDE来告诉你字符丢失在哪一行吗?这个错误非常明显。我建议你在使用Android之前先阅读一些Java教程。
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class HomeActivity extends Activity {
private static final String TAG = HomeActivity.class.getSimpleName();
private ImageButton imageButton;
private ImageButton imageButton2;
public ImageButton imageButton4;
public ImageButton imageButton5;
private ImageView imageView;
private ImageView imageView2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
imageButton = (ImageButton) findViewById(R.id.imageButton);
imageButton2 = (ImageButton) findViewById(R.id.imageButton2);
imageButton4 = (ImageButton) findViewById(R.id.imageButton4);
imageButton5 = (ImageButton) findViewById(R.id.imageButton5);
imageView = (ImageView) findViewById(R.id.imageView);
imageView2 = (ImageView) findViewById(R.id.imageView2);
//Single player button click event
imageButton4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),
MainActivity.class);
startActivity(i);
finish();
}});
//multi player game button event
imageButton5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),
MultiPlayer.class);
startActivity(i);
finish();
}});
//Settings button event
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),
MusicActivity.class);
startActivity(i);
finish();
}
});
}}