设置菜单类时出错

时间:2014-01-23 15:56:30

标签: java android menu

在android

中设置新菜单时,下面的块会引发错误
@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();
    }
}

1 个答案:

答案 0 :(得分:0)

从以下行中删除逗号

Class ourClass=Class.forName("com.example.newtrynow.", + ncall );

应该是这样的

  Class ourClass=Class.forName("com.example.newtrynow." + ncall );