Java 在Android Eclipse开发中实现多个图像按钮时出错
我正在尝试创建一个简单的android问答应用程序。我已经成功地创建了activity类和xml文件,没有显示任何错误。但是当我在模拟器中运行程序时,一旦它到达我有多个图像按钮的特定活动类,程序就会意外停止。我不知道该怎么办。需要帮助 这是我的logcat的一个示例。 ![在此处输入图像描述][1] 这是我的密码Java 在Android Eclipse开发中实现多个图像按钮时出错,java,android,eclipse,Java,Android,Eclipse,我正在尝试创建一个简单的android问答应用程序。我已经成功地创建了activity类和xml文件,没有显示任何错误。但是当我在模拟器中运行程序时,一旦它到达我有多个图像按钮的特定活动类,程序就会意外停止。我不知道该怎么办。需要帮助 这是我的logcat的一个示例。 ![在此处输入图像描述][1] 这是我的密码 package com.example.brainlab; import android.os.Bundle; import android.app.Activity; import
package com.example.brainlab;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
//import android.widget.TextView;
import android.widget.Toast;
public class Question9 extends Activity implements OnClickListener{
private ImageButton button1;
private ImageButton button2;
private ImageButton button3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_queston9);
button1 = (ImageButton) findViewById(R.id.imageButton1);
button1.setOnClickListener(this);
button2 = (ImageButton) findViewById(R.id.imageButton2);
button2.setOnClickListener(this);
button3 = (ImageButton) findViewById(R.id.imageButton3);
button3.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.question1, menu);
return true;
}
@Override
public void onClick(View v) {
Intent intent = new Intent(Question9.this, Question2.class);
switch(v.getId()){
case (R.id.imageButton1):{
Toast.makeText(getApplicationContext(), "Answer saved.", Toast.LENGTH_SHORT).show();
startActivity(intent);
}
break;
case (R.id.imageButton2):
{
Toast.makeText(getApplicationContext(), "Answer saved.", Toast.LENGTH_SHORT).show();
startActivity(intent);
}
break;
case (R.id.imageButton3):
{
Toast.makeText(getApplicationContext(), "Answer saved.", Toast.LENGTH_SHORT).show();
startActivity(intent);
}
}
}
}
我想你的
开关盒是错的。试着用下面的句子来纠正
switch(v.getId()){
case R.id.imageButton1:
//Do your job
break;
case R.id.imageButton2:
//Do your job
break;
case R.id.imageButton3:
//Do your job
break;
default:
break;
}
谢谢。我把它修好了。我还遇到了一个问题,即我所做的清单文件中没有声明活动。现在一切正常了。@user3612120在你的问题中发布你的日志。