public class T2{      
Long a = new Long(14);
void test1(){
long b = a.longValue();
System.out.println("b=== "+ b); 
}

public  void main(String[] args){
test1();
}   
}D:\javatest>java T2
Exception in thread "main" java.lang.NoSuchMethodError: main错在哪里

解决方案 »

  1.   

    public static void main(String[] args)
      

  2.   

    public static void main(String[] args)之后D:\javatest>javac T2.java
    T2.java:9: 无法从静态上下文中引用非静态 方法 test1()
                    test1();
                    ^
      

  3.   

    main是静态方法,要把test1也改成静态才能被main调用。private static void test1(){
      

  4.   

    1楼正解,要写完整
    两种写法
    public class aaa{   
     Long a = new Long(14);
     void test1(){
    long b = a.longValue();
    System.out.println("b=== "+ b);  
    } public void main(String[] args){ 
    aaa test = new aaa();
    test.test1();

    }
    第2种
    public class aaa{   
     static Long a = new Long(14);
     static void test1(){
    long b = a.longValue();
    System.out.println("b=== "+ b);  
    } public static void main(String[] args){ 
       test1();

    }
      

  5.   

    补上,第1种那少写了个static,我调试错误搞忘了
      

  6.   

    public class aaa{   
     Long a = new Long(14);
     void test1(){
    long b = a.longValue();
    System.out.println("b=== "+ b);   
    }  public void main(String[] args){  
    aaa test = new aaa();
    test.test1();
    }  
    }
    第2种
    public class aaa{   
     static Long a = new Long(14);
     static void test1(){
    long b = a.longValue();
    System.out.println("b=== "+ b);   
    }  public static void main(String[] args){  
      test1();
    }  
    }
    就这两种 好好看看 楼主学JAVA多久?
      

  7.   

    main要定义为静态方法,修改为public static void main(String[] args)
    因为test1()是实例方法,不能在静态方法里面调用,故在原来的test1()方法签名上改为 static void test1()
      

  8.   

    静态类,实现的方法必须是静态。如果该方法不是静态,那么得实现实例化该类,如,T2 test = new T2();