aspose file tools*
The moose likes Beginning Java and the fly likes Java problem: Could not find or load class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java problem: Could not find or load class" Watch "Java problem: Could not find or load class" New topic
Author

Java problem: Could not find or load class

bolisetti sriharsha
Greenhorn

Joined: Sep 02, 2011
Posts: 8
I am new to java but previously i did some basic programs on my system.... i never got this error message....so i removed java sdk and reinstalled it...
i set PATH variable as C:\Program Files\Java\jdk1.7.0\bin
CLASSPATH variable as C:\Program Files\Java\jdk1.7.0\lib
JAVA_HOME as C:\Program Files\Java\jdk1.7.0

i am unable to run even programs which i executed earlier...
when i compile them ... it is not showing any error message but when i tried to run them(by using java command in command prompt) iam getting error message as "Error: Could not find or load main class Applicant"

PLZZZZ Help me Guys........... sorry for my poor english

THANKS IN ADVANCE
Ganesh Akondi
Greenhorn

Joined: Jul 13, 2011
Posts: 6

To check whether JDK got installed properly or not..open command prompt and type javac ->enter
You should get some list of options instead of an error message like javac is not an internal command.
Then you have installed your JDK properly.

Differences between PATH and CLASSPATH is: (both are environmental variables)
PATH - points to bin of your java installation (system variable to tell the OS where is your JDK installed)
CLASSPATH - can say java variable, which is used to tell locations of all jar/zip(classes) files to Compiler.
Classpath is nothing but setting up the environment for Java. Java will use to find compiled classes
eg: If we are using JDBC Driver then we need to keep classes12.jar in classpath, If we are using sevlets future then we need to keep servlet-api.jar in classpath ..
like these so many places we use this.
bolisetti sriharsha
Greenhorn

Joined: Sep 02, 2011
Posts: 8
Thanks for the reply..... when i typed javac and pressed enter.... it shows ..as you said a list of options.... so jdk is installed properly..


BUT STILL I AM UNABLE to exceute java programs
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
This might help - http://www.coderanch.com/t/412282/java/java/we-change-tha-java-version and http://download.oracle.com/javase/tutorial/getStarted/problems/index.html and http://www.coderanch.com/how-to/java/how-to-create-java-program

If you still have a problem, please post the simple java class you intend to run and copy paste the exact error shown in the cmd prompt.
bolisetti sriharsha
Greenhorn

Joined: Sep 02, 2011
Posts: 8

MY PROGRAM



The error i am getting in command prompt

D:\stuff\prgms>java hello
Error: Could not find or load main class hello




John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Hi Bolisetti,

1. You have to compile your java class first using the javac command before running it using the java command.
2. I hope you have placed the hello.java (or the .java file you have named) in the D:\stuff\prgms folder.
3. After you compile using javac hello.java you check whether a class file Hello.class is generated in the D:\stuff\prgms folder
4. Then you can execute the class using the command java Hello

Additionally, you do not need to import java.lang package as automatically all the classes in the package gets imported.

And please UseCodeTags

And a warm welcome to the Ranch
Ganesh Akondi
Greenhorn

Joined: Jul 13, 2011
Posts: 6

Yes..i second John.

D:\stuff\prgms>javac hello
check manually whether hello.class got created in that folder
then
D:\stuff\prgms>java hello

and as John said, java.lang in base package for java... no need of importing it explicitly.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Hi Ganesh - Welcome to the Ranch
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38756
    
  23
Are you writing java hello or java Hello? If the class is called Hello, you must not try hello, because Java is case-sensitive.

Try java -cp . Hello

If that works:
Have you set a classpath? Try ECHO %CLASSPATH% (Windows®) or echo $CLASSPATH (*nix). If you have a CLASSPATH set at all, who set it? If you set it yourself, you are probably best off deleting it. If it was set by another application (for example, Quicktime sets itself a system CLASSPATH), edit it by adding . (dot meaning "current working directory") at its beginning, followed by the separator (; for Windows® or : for *nix).

Lots of people, and some books, tell you about the importance of a system CLASSPATH, but it usually does more harm than good, and that advice is mistaken.
bolisetti sriharsha
Greenhorn

Joined: Sep 02, 2011
Posts: 8
Thanks every one for your answers....
Campbell Ritchie .....Thank You Very Much...you really solved my problem.... But i have a small query what is -cp. and how should i set classpath .....



John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
You are welcome

cp is an option to specify the class path - the path where to find the class files.

Campbell has suggested to use java -cp . Hello which means search for the class "Hello" in the current working folder (specified by the "." after the -cp option)

So if you have your Hello.class in some other folder say C:/Classes then you have to give the command like java -cp C:/Classes Hello
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java problem: Could not find or load class