switch(exp)中的exp是有限值的,必须是char,byte,short或int型中的一种,不允许使用boolean型,其他的像你说的Button,List就更不行了。表达式一定要转化为int型,case后面也应该是int型的。去看看书吧,switch语法方面书上讲的很清楚的。祝你好运!

解决方案 »

  1.   

    可以是数值类型,即byte short int long四种
    但是不能为其它类型
      

  2.   

    不可以,只能是 byte char short int .long 不可以!!!!
      

  3.   


    我还没注意你说的是char
    好像我记得char是不行的啊
    只能是数值类型的啊
      

  4.   

    只能是char, byte, short 和int中的一种。我上面说的已经很明白了。唉,其实只要去看看语法就行了。
      

  5.   

    那用Button.toString()来转的话,转过来的是Button的name还是标示阿?
      

  6.   

    byte char short int are surpport
    String 是不可以的
    但是可以采用个折中的方法
    就是取Button.toString()的第一个char来标示   不行还可以在分支用第二个char
      

  7.   

    Button.toString should return the name of Button.I think you can try to run the program to see, and don't forget to post the result. :)
      

  8.   

    char byte short int四种可以
      

  9.   

    看书看书看书!!!!!!《Java宝典》
      

  10.   

    Button.toString转换为字符串后好像带它在内存的地址,也可以将地址部分转换为数字进行switch,不过这样也够麻烦的。
      

  11.   

    cherami(cherami) 说得对,我试了一下,Button.toString转换为字符串后返回的是它在内存的地址,而不是Button的name或标示。给cherami(cherami)加20分。