why wrong name with NoClassDefFoundError

前端 未结 3 1866
忘了有多久
忘了有多久 2021-01-17 03:24

I created a List.java file in folder UtilityPack which contains this code

package Utilities;
public class List
{
    private class          


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-17 04:02

    You need the fully qualified name e.g.

    java -cp . Utilities.List
    

    i.e. you're telling the JVM to look from the current direct (-cp .) for a class Utilities.List, which it will expect in the file Utilities\List.class.

    To be more consistent you should put the .java file under a Utilities directory (yes - this is tautologous - the package specifies this, but it's consistent practise).

    I would also avoid calling your class List. At some stage you're going to import a java.util.List and it'll all get very confusing!

    Finally, as soon as you get more than a couple of classes, investigate ant or another build tool, and separate your source and target directories.

提交回复
热议问题