Reputation:
I am facing this problem while trying to run my java file by writing java filename ....
I have read on many pages the possible ways this could be corrected but unfortunately I have been unable to correct my problem...
First of all I looked at my environment variables and observed that there was no CLASSPATH set and I had pointed PATH correctly to my jre as well as jdk bin in C:\
Second I am able to run javac filename.java and observe that .class file gets built in the local directory.
While writing javac -classpath . filename works writing java -classpath . filename (without .class) results in the same error.
I just don't know how to run my program in command prompt!!!! Please do not give me links to the pages which have given the same answers that I have mentioned above as they do not work in my case.....
Please help....
Upvotes: 1
Views: 3784
Reputation: 10184
Stating javac filename.java and java filename are not enough for this really.
We also need to know the contents of the filename.java or at least the first few lines.
This is the expected way to declare a class
public class Filename {
}
This is the way it would have to be to work given your example: java filename
public class filename {
}
This is could exist too, but you are probably just messing with us :)
public class SomethingElse {
}
Overall no matter what the filename is on the filesystem, the class has a name and that is the name that the java command is expecting. I would recommend using the upper case first letter form as it is clearer imo
Upvotes: 0
Reputation: 74750
There is a bit little information in your post ... as said, a complete example would really help solving this. Some ideas:
filename
? If not, you should make sure to call the right class name in the java command.java
not being able to find it. Make sure that the class name is the same as the file name.Upvotes: 0
Reputation: 420951
Note that if your class resides in some package mypackage
, you need to make sure the class file is inside mypackage/
and do
java -classpath . mypackage.YourClass
Upvotes: 3