linux - [Solved-5 Solutions] Error: Could not find or load main class - ubuntu - red hat - debian - linux server - linux pc
Linux - Problem :
The following code compiles without error:
However, when you try to run the following:
You get the following error: "Error: Could not find or load main class SpatialModel ".
Linux - Solution 1:
Make sure that you add the location of your .class file to your classpath. So, if its in the current folder then add . to your classpath. Note that the windows classpath separator is a semi-colon ie ;
Linux - Solution 2:
If the class is in a package
Then calling:
Results in Error: Could not find or load main class TheClassName.
This thepackagename directory must exist in the classpath. In this example, ., meaning the current directory, is the entirety of classpath. Therefore this particular example must be called from the directory in which thepackagename exists.
To be clear, the name of this class is not TheClassName, It's thepackagename.TheClassName. Attempting to execute TheClassName does not work, because no class having that name exists. Not on the current classpath anyway.
Linux - Solution 3:
You can try these two when you are getting the error: 'could not find or load main class'
If your class file is saved in following directory with HelloWorld program name d:\sample
java -cp d:\sample HelloWorld
java -cp . HelloWorld
Linux - Solution 4:
You need to add the current directory to the Java classpath
Linux - Solution 5:
You have to include classpath to your javac and java commands
Package Named: com.test Class Name: Hello (Having main) file is located inside "src/com/test/Hello.java"
Related Searches to - linux - linux tutorial - Error: Could not find or load main class
linux red hat debian opensuse ubuntu arch linux mandrake get link linux computer linux pc linux server linux desktop learn linux red hat linux red hat enterprise linux linux software linux tutorial linux operating system suse linux linux download linux os linux ubuntu vmware linux lunix linux windows linux news linux usb linux commands unix linux linux version what is linux linux centos linux ftp error could not find or load main class command prompterror could not find or load main class eclipse javaerror could not find or load main class eclipse scalaerror could not find or load main class spring booterror could not find or load main class intellijerror: could not find or load main class mavenerror: could not find or load main class linuxerror: could not find or load main class netbeans