在 Android 中设置新菜单时,下面的 block 会抛出错误
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String ncall = Classes[position];
try {
Class ourClass=Class.forName("com.example.newtrynow.", + ncall );
\\above line shows error, why is "+" not supported its just appending the rest of string
Intent ourIntent=new Intent(Menu.this, ourClass);
startActivity(ourIntent);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
最佳答案
删除以下行中的逗号
Class ourClass=Class.forName("com.example.newtrynow.", + ncall );
应该是这样的
Class ourClass=Class.forName("com.example.newtrynow." + ncall );
关于java - 设置菜单类时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21313189/