Java 根据选中的复选框启动三个活动之一
我创建了一个包含4个活动的应用程序:登录、运动、技术和运动技术。 登录活动,在列表视图中包含两个名为“运动和技术”的复选框和一个按钮,当按下按钮时,程序将检查复选框的文本,并根据其打开正确的活动,如果仅选中了“运动”复选框,则应打开“运动”活动,如果仅选中了“技术”复选框,则会打开“技术”活动;如果选中了两个复选框,则会打开一个名为“sporttecknology”的活动。 运行应用程序时,当我仅选中“运动”复选框并按下按钮时,将打开运动活动。但当我只选中“技术”复选框,然后按下按钮时,应用程序停止工作,当我选中两个复选框,然后按下按钮时,也会发生这种情况 那么我的代码中有错误吗 私有无效检查按钮单击{Java 根据选中的复选框启动三个活动之一,java,android,android-activity,checkbox,android-listview,Java,Android,Android Activity,Checkbox,Android Listview,我创建了一个包含4个活动的应用程序:登录、运动、技术和运动技术。 登录活动,在列表视图中包含两个名为“运动和技术”的复选框和一个按钮,当按下按钮时,程序将检查复选框的文本,并根据其打开正确的活动,如果仅选中了“运动”复选框,则应打开“运动”活动,如果仅选中了“技术”复选框,则会打开“技术”活动;如果选中了两个复选框,则会打开一个名为“sporttecknology”的活动。 运行应用程序时,当我仅选中“运动”复选框并按下按钮时,将打开运动活动。但当我只选中“技术”复选框,然后按下按钮时,应用程序
Button myButton = (Button) findViewById(R.id.findSelected);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringBuffer responseText = new StringBuffer();
//responseText.append("The following were selected...\n");
ArrayList<Interestclass> interestList = dataAdapter.interestList;
for (int i = 0; i < interestList.size(); i++) {
Interestclass interest = interestList.get(i);
if (interest.isSelected()) {
responseText.append(interest.getName());//"\n" +
}
}
Toast.makeText(getApplicationContext(), responseText, Toast.LENGTH_LONG).show();
String start = responseText.toString();
if (start.equals("Sport")) {
Intent intentSport = new Intent(MainActivity.this, Sport.class);
startActivity(intentSport);
}
else if (start.equals("Technology")) {
Intent intentTechnology = new Intent(MainActivity.this, Technology.class);
startActivity(intentTechnology);
}
else if (start.equals("SportTechnology")) {
Intent intentSportTech = new Intent(MainActivity.this, SportTechnology.class);
startActivity(intentSportTech);
}
else {
Intent intentTechnology = new Intent(MainActivity.this, Technology.class);
startActivity(intentTechnology);
}
错误是什么?你能提供你的logcat吗?你在mainfest文件中声明了所有的类吗?它没有给我一个错误,但是当我在模拟器上运行它时,它停止了工作,我不知道什么是logcat,因为我是android的新手,在那里我可以得到它来提供它。是的,我在mainfest文件中声明了它们。logcat允许你查看e系统的调试输出。如果您阅读红线,它应该是这样的,它们会告诉您在发生崩溃时调用异常的位置,以及引发的异常类型。这对于调试应用程序非常有用。这是Logcat中的前两行:java.lang.RuntimeException:无法实例化activity ComponentInfo{com.newsapp.mynewsapp/com.newsapp.mynewsapp.Technology}:java.lang.ClassCastException:com.newsapp.mynewsapp.Technology无法强制转换为android.app.Activity
});
}