//在main()函数前加static关键字,如下:
java.lang.NoSuchMethodError: main . public class keyi
{
 int  order,d,       b1=2,b2=6,b3=24;  String output="",
           a1="very good",
           a2="much better",
           a3="the best",
           a="it's ",
           word;
  public void keyi ()
  {  } public void methods (int e)
       {
         switch (e)
        {
         case 1:word=a+a1;
         output+=word;
         break ;         case 2:word=a+a2;
         output+=word;
         break;         case 3:word=a+a3;
         output+=word;
         break;
        }         return;
       }public   int method (int b)     {
       int y;
       if (b%6==0)
         if(b%8==0)
          y=3;
         else y=2;
       else
         y=1;       return y;
      }public  static void main ( String [] args){  order=1+(int)((Math.random())*3);     switch(order)
      {
         case 1:
         d=method(b1);
         methods(d);
         break;         case 2:
         d=method(b2);
         methods(d);
         break;         case 3:
         d=method(b3);
         methods(d);
         break;
     }   System.out.println("please press the key enter\r");
     System.out.println("hello,"+output);
  System.exit(0); }
}

解决方案 »

  1.   

    public  void main ( String [] args)错了应该是public static void main ( String [] args)才对main方法必须是这样写的!若不这样写就成了普通方法了
      

  2.   

    public class keyi
    {
     static int order,d,       b1=2,b2=6,b3=24;  static String output="",
               a1="very good",
               a2="much better",
               a3="the best",
               a="it's ",
               word;
      public void keyi ()
      {  } public static void methods (int e)
           {
             switch (e)
            {
             case 1:word=a+a1;
             output+=word;
             break ;         case 2:word=a+a2;
             output+=word;
             break;         case 3:word=a+a3;
             output+=word;
             break;
            }         return;
           }public  static int method (int b)     {
           int y;
           if (b%6==0)
             if(b%8==0)
              y=3;
             else y=2;
           else
             y=1;       return y;
          }public static void main( String [] args){  order=1+(int)((Math.random())*3);     switch(order)
          {
             case 1:
             d=method(b1);
             methods(d);
             break;         case 2:
             d=method(b2);
             methods(d);
             break;         case 3:
             d=method(b3);
             methods(d);
             break;
         }   System.out.println("please press the key enter\r");
         System.out.println("hello,"+output);
      System.exit(0); }
    }
      

  3.   

    加了static以后编译就通不过了,还请指教。
      

  4.   

    而且出现很多错误,加了static以后。
      

  5.   

    main()函数前怎么没有static关键字?
      

  6.   

    谢谢,现在终于明白了static的重要作用,谢谢。
      

  7.   

    public class Keyi {
    static int  order,d;
    static int b1=2,b2=6,b3=24;
    static String output="",a1="very good",a2="much better",a3="the best",a="it's ",word;

    public void keyi () {

    }

    public static void methods (int e) {
             switch (e){
            case 1: word=a+a1;
              output+=word;
              break ;

            case 2: word=a+a2;
              output+=word;
              break;
            case 3: word=a+a3;
              output+=word;
              break;
            }
              return;
           } public static int method (int b){
            int y;
            if (b%6==0)
              if(b%8==0)
               y=3;
              else
              y=2;
            else
              y=1;        return y;
           } public static void main ( String [] args) {
    order=1+(int)((Math.random())*3);
    switch(order){
              case 1: d=method(b1);
              methods(d);
              break;
            case 2: d=method(b2);
              methods(d);
              break;
            case 3: d=method(b3);
              methods(d);
              break;
          }
    System.out.println("please press the key enter\r");
          System.out.println("hello,"+output);
       System.exit(0);
    }
    }
      

  8.   

    构造函数public void keyi(){}  不对,构造函数不能有类型,去掉void
      

  9.   

    public  void main ( String [] args)错了应该是public static void main ( String [] args)才对main方法必须是这样写的!若不这样写就成了普通方法了