static String getstring()throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
String s=br.readLine();
return s;
}
写了一个方法,从键盘接受一个串,爱主函数里面调用,出现错误提示:
StackX.java:93: 未报告的异常 java.io.IOException;必须对其进行捕捉或声明以便抛出                        input=getstring();
                                       ^
1 错误
,该怎么解决啊?

解决方案 »

  1.   

            try
            {
                input=getstring();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }增加处理异常就可以了
      

  2.   

    String s = null;
    BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
    try {
    System.out.println("请输入您需要的:");
    s=in.readLine();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    return s;
    这样写