try{
System.out.print("请输入坐标x值");
n1=KeyInput.readInt();

}catch(Exception NumberFormatException){
System.out.println("输入错误!"); 
break ;
}Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
break cannot be used outside of a loop or a switch

解决方案 »

  1.   

    break只能用在while switch for 等语句块中,哪有在try catch 里用的
      

  2.   


    return 
    void xx(){
    也可以使用return ,楼主可能不知道
    }
      

  3.   


     没见过在try catch中用的。  而且貌似没意义
      

  4.   

    捕获异常的话,不是自动终止程序了吗,自动退出了,用break想干嘛?
      

  5.   

    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    break cannot be used outside of a loop or a switch
    报的异常已经很明确了异常出现在主线程中:无法解决的编译问题,break只能用在loop和switch中
      

  6.   

    我上边的忘记说了
    我是放在while里的
    do{
    try{ 
    System.out.print("请输入坐标x值"); 
    n1=KeyInput.readInt(); }catch(Exception NumberFormatException){ 
    System.out.println("输入错误!"); 
    break ; 

    }while(true)
      

  7.   

    试了一下,没问题啊
    Exception NumberFormatException必要用类名作为变量
    while(true);不要忘了加;