静态方法中只能应用静态方法和静态变量
你的main方法是static,引用的methodA也必须是static

解决方案 »

  1.   

    non-static method methodA() cannot be referenced from a static context methodA();//非静态方法,不能在静态方法中直接调用
    import java.io.IOException;
    public class ExceptionTest
    {  public static void main (String args[])
    {
    ExceptionTest et = new ExceptionTest();
    try
    {
    et.methodA();

    catch (IOException e)
    {
    System.out.println("Cautht IOException");
    } catch (Exception e){
    System.out.println("Caught Exception");
    }
    }
    public  void methodA(){
    throw new IOException();
    }
    }
    就可以了
    产生IOException时,输出为Cautht IOException。
    产生其他异常时如/0等,输出为Caught Exception
      

  2.   

    1。不能在静态方法里调用非静态方法。
    2。当然是有IOException抛出的时候,就是methodA运行
    3。....
    4。不运行
      

  3.   

    几个错误,
    1,静态方法不能调用非静态方法,解决方法参照上面。
    2,methodA()既然要抛异常,就必须声明:
    public  void methodA() throws IOException3,仅就本程序而言,必然会出IO异常,Caught Exception要抛出别的异常才会引发
      

  4.   

    1.出结果为:non-static method methodA() cannot be referenced from a static context methodA();//这句话怎么理解??
     
    解决:你要看看书了,在静态上下文中不能引用非静态方法methodA(),解决办法有两个:1)把public void methodA()改为public static void methodA()
    2)在main()中加一句ExceptionTest et=new ExceptionTest();然后再在try{}中把methodA(),改为et.methodA()
    这样就解决了第一个问题,不过你的程序还有问题的,看下去
    2.什么情况下输出为Cautht IOException?
    解决:你这个程序有问题,方法methodA()中throw了一个IO异常,而且没有再抛出就是throws,那么必须在抛出的地方解决。你需要看看throws和throw。解决办法:把public static void methodA()后面加上throws IOException。这样就OK了,输出为Caught IOException.3.什么情况下输出为Caught Exception?
    解决:你去看看异常的类结构,这程序改不出Caught Exception的结果的。
      

  5.   

    4. 这个程序强制抛出了一个IOException,所以一定有输出结果为Caught IOException
      

  6.   

    (2001-12-27 10:38:45)      天水蓝
    non-static method里不能声明静态变量,这句话对不?
    例如:
    public int aMethod() {
    static int  i= 0;
    i++;
    return i;
    }