我在片段中有一个列表,当我按下该列表中的某些内容时,我希望启动一个新活动。我只尝试了我的第一个选项,但是当我尝试它时,我得到了错误:
03-20 15:16:13.017: E/AndroidRuntime(941): Caused by: java.lang.ClassCastException: com.test.test.Algebra cannot be cast to android.app.Activity
这是我的片段类:
public class FragmentTest extends SherlockListFragment {
String formler[]= {
"Algebra",
"Aritmetik",
"Differential- och integralkalkyl",
"Funktioner",
"Geometri",
"Komplexa tal",
"Statistik och sannolikhet",
"Trigonometri"
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
setListAdapter(new ArrayAdapter<String>(getActivity().getBaseContext(), android.R.layout.simple_list_item_1, formler));
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String choice = formler[position];
try{
@SuppressWarnings("rawtypes")
Class choiceClass = Class.forName("com.test.test." + choice);
Intent startIntent = new Intent(getActivity().getBaseContext(), choiceClass);
startActivity(startIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
我究竟做错了什么?