繁体   English   中英

运行Java程序时发生ClassNotFoundError

[英]ClassNotFoundError while running java program

我正在使用.sh文件运行程序。 .java文件具有main()方法,并且在其中具有从其他.java文件的类实例化的对象。 它编译成功,但是当执行该文件时,显示`

ClassNotFoundException

in the main() method for the first object creation, even though there was a .class file created for FetchData method for the first object creation, even though there was a .class file created for

package scheduledExecutor;

public class Executor
{
    public static void main()
    {
        ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
        FetchData task= new FetchData(); -- show error here for ClassNotFound
        executor.scheduleAtFixedRate(task, 1, 310, TimeUnit.SECONDS);
    }
}

谁能帮忙吗?

尝试将FetchData类位置放在文件路径中,看看是否可行

当编译器的路径包括该类但JVM的ClassPath不包括目标类时,您将在执行时而不是在编译期间得到ClassNotFoundException。

运行程序时,请确保包含FetchData类文件的文件夹或jar在JVM的ClassPath中。 查看编译器的类路径和JVM使用的类路径之间的区别。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM