码迷,mamicode.com
首页 > 其他好文 > 详细

错误: 在类 com.zs.container.CollectionData 中找不到主方法, 请将主方法定义为: public static void main(String[] args)

时间:2015-03-29 15:10:29      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:main   java   

错误: 在类 com.zs.container.CollectionData 中找不到主方法, 请将主方法定义为:

   public static void main(String[] args)


package com.zs.container;
import java.util.ArrayList;
import com.java.array.generator.CountingGenerator.String;

import com.java.array.generator.CountingGenerator;
import com.java.array.generator.Generator;


public class CollectionData<T> extends ArrayList<T> {
    public CollectionData(Generator<T> gen, int quantity) {
        for (int i = 0; i < quantity; i++)
            add(gen.next());
    }
    // A generic convenience method:
    public static <T> CollectionData<T> list(Generator<T> gen, int quantity) {
        return new CollectionData<T>(gen, quantity);
    }
    public static void main(String[] args) {
        System.out.println("start");
        Generator<java.lang.String> gen =new CountingGenerator.String();
        ArrayList<java.lang.String> list=new CollectionData<java.lang.String>(gen,8);
        System.out.println(list);
    }
}

Error: the class com. Zs. Container. Can‘t find the main method in the CollectionData, please will be the main method is defined as: Public static void main (String [] args)

what‘s wrong? of course i have the main method!why error happened??

suprise!when i remove this line " import com.java.array.generator.CountingGenerator.String;" it works well!why???

the com.java.array.generator.CountingGenerator.String code:

package com.java.array.generator;

 public class CountingGenerator {

    static char[] chars = ("abcdefghijklmnopqrstuvwxyz"
            + "ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();

    public static class Character implements Generator<java.lang.Character> {
        int index = -1;

        public java.lang.Character next() {
            index = (index + 1) % chars.length;
            return chars[index];
        }
    }
    public static class String implements Generator<java.lang.String> {
        private int length = 7;
        Generator<java.lang.Character> cg = new Character();

        public String() {
        }

        public String(int length) {
            this.length = length;
        }

        public java.lang.String next() {
            char[] buf = new char[length];
            for (int i = 0; i < length; i++)
                buf[i] = cg.next();
            return new java.lang.String(buf);
        }
    }
} 


解决:

Use

public static void main(java.langString[] args)

Why? Because the String is interpreted as

import com.java.array.generator.CountingGenerator.String;


错误: 在类 com.zs.container.CollectionData 中找不到主方法, 请将主方法定义为: public static void main(String[] args)

标签:main   java   

原文地址:http://blog.csdn.net/lemon89/article/details/44726919

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!