public class HelloWorld
   {
      public  void main(String args[])
         {
            System.out.println(this.getClass().getName());
            for (int i=0;i<args.length;i++)
                   System.out.println(args[i]);  
         }
   }
 为什么会出错呢System.out.println(this.getClass().getName());

解决方案 »

  1.   

    首先,铁出来的程序不是你机器里面的程序,main()漏掉了static。
    其次,static方法实际上是在一个类里面寄居,而不是真正这个类的成员,所以他说什么“俺的祖国叫XXX”不可能有作用的。
    主程序概念也许在Java中已经过时。
      

  2.   


    第一,你的main方法不是static的。第二,在static方法里不能用thispublic class HelloWorld
    {
    public void echo(){
      System.out.println(this.getClass().getName());
    }
     public static void main(String args[])
     {
      HelloWorld h = new HelloWorld();
      h.echo();
     }
    }
      

  3.   

    public class HelloWorld
      {
          public static void main(String args[])
            {
                System.out.println(this.getClass().getName());
                for (int i=0;i<args.length;i++)
                      System.out.println(args[i]);  
            }
      }
    那应怎么办呢,我是刚学
      

  4.   

    sharetop(天生不笨) :
       你一说,我就记起,static方法里不能用thispublic class HelloWorld
    {
        public void echo(){
          System.out.println(this.getClass().getName());    
        }
    public static void main(String args[])
    {
        HelloWorld h = new HelloWorld();
        h.echo();
    }
    好的不错,我意思理解了,
    与其这样做,还不如这样了  :) :) :)public class HelloWorld
      {
          public static void main(String args[])
            {
                System.out.println("My Program Name is "+"HelloWorld");
                for (int i=0;i<args.length;i++)
                      System.out.println(args[i]);  
            }
      }
      

  5.   

    我发现,程序名如(HelloWorld.java)
    与主类名(class HelloWorld) 必须一致,
    否则编译出错:找不到主类