简体   繁体   中英

ClassNotFoundError while running java program

I am running a program using a .sh file. The .java file has the main() method and inside it I have an object instantiated from a class of other .java files. It compiled successfully, but when it comes down to executing the file, it shows `

ClassNotFoundException

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

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);
    }
}

Can anyone please help?

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

You get a ClassNotFoundException at execution time but not during compilation when the path for the compiler includes the class but the ClassPath for the JVM does not include the target class.

Make sure the folder or jar that contains the FetchData class file is in the ClassPath of the JVM when you run the program. Look at the difference between the compiler's Classpath and the one used by the JVM.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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