static部分是在main函数前执行的,这有什么奇怪的

解决方案 »

  1.   

    少了main()函数!
    我一般程序都是以public static void main(String args[]){}结尾的!
      

  2.   

    public class Hello
    {
    public static void main (String [] args)
    {
    System.out.println("Hello,world");
    }
    }
      

  3.   

    jvm默认 public static void main (String[] args)为程序入口
      

  4.   

    Exception in thread "main" java.lang.NoSuchMethodError: main 
    //是没有mainHello,world
    //static部分是在解释时就装入的在main函数前执行
      

  5.   

    Exception in thread "main" java.lang.NoSuchMethodError: main
    怎么将这句去掉啊!!
      

  6.   

    应加点,  public static void main( String[] args)
      

  7.   

    你缺少主函数(Main)
    public class Hello
    {
    public static void mian(string args[])
    {
    System.out.println("Hello,world");
    }
    }
    再试试看呢
      

  8.   

    Exception in thread "main" java.lang.NoSuchMethodError: main
    怎么将这句去掉啊!!
      
      

  9.   

    public class Hello
    {
    public static void main(String args[])
    {
    System.out.println("Hello,world");
    }
    }试试.
      

  10.   

    好的,参与一下^_^
    public class Hello{
      static{
        System.out.println("Hello,world");
      }
      public static void main(String[] args){}
    }//:-)
      

  11.   

    public class Hello
    {
    static
    {
    System.out.println("Hello,world");
        System.exit(0);
    }

    }
    我试试了
    这样好用!~
      

  12.   

    public class Hello
    {
    static
    {
    System.out.println("Hello,world");
        System.exit(0);
    }

    }
    我试试了
    这样好用!~
      

  13.   

    public class Hello
    {
    static
    {
    System.out.println("Hello,world");
    }
    public static void main(String[] args)
    {
    System.out.println("test"); }
    }
      

  14.   

    import java.util.*;public class ConstructorTest
    {
    public static void main(String[] args)
    {
    //fill the staff array with three Employee objects
    Employee[] staff= new Employee[3];
    staff[0] = new Employee("harry",40000);
    staff[1] = new Employee(60000);
    staff[2] = new Employee();

    //print out information about all employee objects
    for(int i=0;i<staff.length;i++)
    {
    Employee e = staff[i];
    System.out.println("name="+e.getName()+",id"+e.getId()+",salary"+e.getSalary());
    }
        }
    }
    class Employee
    {
    //three overloaded constructors
    public Employee(String n,double s)
    {
    name = n;
    salary = s;
    }
    public Employee(double s)
    {
    //calls the Employee(String,double) construcor
     this ("Employee #"+nextId,s);
    }
    //the default constructor
    public Employee()
    {

    }

    public String getName()
    {
    return name;
    }
    public double getSalary()
    {
    return salary;
    }
    public int getId()
    {
    return id;
    }
    //object initialization block

    public void setId()
    {
    id = nextId;
    nextId++;
    }
    //static initialization block

    static 
    {
    Random generator =new Random();
    //set nextId to a random number between 0 and 9999
        nextId = generator.nextInt(10000);
     }
     private String name = "";
     private double salary;
     private int id;
     private static int nextId;
    }
    ConstructorTest.java:66: illegal forward reference
                        nextId = generator.nextInt(10000);
                        ^
    1 error
    在帮忙看看!!
      

  15.   

    就是少了 main函数了,为
    public class Hello
    {
      public static void main(String[] args)
      {
        System.out.println("Hello World!");
      }
    }
      

  16.   

    在编译时,static部分是首先进行编译的。
      

  17.   

    试一下把field
         private String name = "";
         private double salary;
         private int id;
         private static int nextId;
    剪到最前面去。偶用SDK1.5编译不用改就通过
    name=harry,id0,salary40000.0
    name=Employee #2706,id0,salary60000.0
    name=,id0,salary0.0
      

  18.   

    public class Hello
    {
    static
    {
    System.out.println("Hello,world");
    }
    }
    看到这段代码,可以编译通过,解释也通过,但是没有main()函数,你如何运行这程序?
    只有在注入java Hello是就会有这个异常
    Exception in thread "main" java.lang.NoSuchMethodError: main
      

  19.   

    public class Hello
    {
    public static void main(String args[])
    {
    System.out.println("Hello,world");
    }
    }
      

  20.   

    程序的入口应该是
    public static void main(String[] args)
    {}参数String[] arg或者String args[]
    都可以如果没有入口,则程序不知道该从什么地方执行,出现错误
      

  21.   

    public class test6
    {
       public test6()
       {
       }  public static void main(String[] args)
       {
          System.out.println("Hello World!");
      }
    }
      

  22.   

    public class Hello
    {
    public static void main(String[] args)
    {
    System.out.println("Hello,world");
    }
    }
    如是即可
      

  23.   

    一个java类的执行,都是先从main开始的,这是java编程的规范