簡體   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