run time error: could not find or load main class
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Please help me out.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I hope you tried like below
java HelloWorld
and if the HelloWorld.class file is in different location say C:/MyClasses then try,
java -cp C:/MyClasses HelloWorld
where -cp specifies the classpath ( location of the .class files)
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The .class file and the .java flies are n the same folder.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Also try java -cp . HelloWorld
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Unrecognized option:-cp.HelloWorld
Error: Could not create the java virtual machine.
Error: A fatal exception has occurred.Program will exit.
yah...m pasting the program..
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
java[space]-cp[space].[space]HelloWorld
and please UseCodeTags henceforth
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Do I need to type java -cp . <class_name> every time I run a prog? Wont the command java <classname> simply work??? Is the CLASSPATH setting correct???
Will you please clarify how to use compile a prog without going into the bin...I mean without typing the complete path address (C:\Java\jdk1.7.0\bin) again and again.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Two things i can think of not using the -cp option is
1. If your .class file is in the same directory then you don't have to specify the class path option
2. If your .class file is present in the subfolders say C:/MyClasses/com/mypackage/HelloWorld.class and com and mypackage are the packages in which the HelloWorld is present. Now say if you are in the location C:/MyClasses in the cmd prompt you can just give java com.mypackage.HelloWorld
I hope you knew about packages - the declaration you give at the start of a java program if needed - say in this case ->
You do not need to specify every time the path of the java.exe. To make the OS to locate the java exe it you have to specify the JAVA_HOME and path variables in the Environment variables.
This post should help you setting the environment variables - https://coderanch.com/t/551943/java/java/Wrong-version-appearing-java-command
and this to understand path & classpath -> http://download.oracle.com/javase/tutorial/essential/environment/paths.html
Also I think Java should be already installed in your OS by default. So just type the command java in your command prompt and see what the output is shown.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
If the classpath was set by another application, edit it by adding the . at the beginning. It will read something like .;C:\something\folder;C:\Program Files\qt\lib;... Quicktime is one of the applications prone to setting a system classpath.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I have set the path as suggested and now I compile the program by simply typing javac <classname>.java
Mr. John, the output which I got by typing java in the command prompt is--
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
but double check whether it is using the version you intend to run your classes using the command java -version
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I have installed JDK7 and I am unaware of the meaning of the last line.I am really grateful for you have taken so much of pain to solve my problem. Thanks a lot.
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
My knowledge is restricted to Java 1.5.... and it would be appropriate for other ranchers who knew 1.7 version to answer your query... hope so you will get that in a moment..
And please start new thread for new questions...
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Have a nice time.See you again.
Good luck!
With regards,
Saptaparna
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Saptaparna Dhar wrote:Thank you for your assistance.
I have set the path as suggested and now I compile the program by simply typing javac <classname>.java
Mr. John, the output which I got by typing java in the command prompt is--
I have a related issue. I am getting the above message and I have entered the command:
Why does this screen appear in the windows command prompt and what can I do to run my program. I created a simple hello world program and used:
andI got the output Hello world, so it must have executed fineactually the same thing is happening to my hello world program too. I do also have a jar file that I needed for jsch-0.1.48.jar in the same folder as the java and .class files. I'd Also like to mention that I ran this in eclipse and it works just fine. I've never used the command prompt to execute java before. Thank you!
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
If you need to write -cp . you have a classpath problem. You ought not to set a system classpath; if you set your own, you ought to delete it. If it was there before you started, eg containing QuickTime entries, add a . for current directory at its beginning. In Windows® it looks like this .;blahblahblah and on other OSs like this .:somethingsomethingsomething. You probably have to reopen the command line to see any effect.
| this llama doesn't want your drama, he just wants this tiny ad for his mama Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |






