This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am very new to java and have searched around this board and tried all the ones I have found so I figured I should ask and see if I could get pointed in the right direction.
I installed the jdk 6.7 I came to the board to figure out how to set the path so now I have user variable setting that is Java_Home with the value C:\Program Files\Java\jdk1.6.0_07\bin in it. Ive done several other things but right now that and the path in system variables being set to %JAVA_HOME%\bin is all that is going on that is different. and it doesnt run if I type in javac still. but will run if I type the whole path in. but still crashes
If I can get help with the path that would be great but more troubling is when i go to the javac.exe and click on it the compiler pops open then quickly words run across it and it closes before I can read anything. so I'm trying to figure out what I'm doing wrong. The most important is getting the compiler to run at all. The path working right would be a bonus.
I don't understand what you mean by " but will run if I type the whole path in. but still crashes" - does it run or does it crash? what EXACTLY is the error message?
I THINK the problem is that you have your JAVA_HOME is set to C:\Program Files\Java\jdk1.6.0_07\bin, and then you put %JAVA_HOME%\bin
that would resolve to
I'd take the \bin off the JAVA_HOME and try again. make sure you open a new command window if you're on windows...
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: Jul 23, 2008
Originally posted by fred rosenberger: I don't understand what you mean by " but will run if I type the whole path in. but still crashes" - does it run or does it crash? what EXACTLY is the error message?
Thank you for your assistance. That did solve the issue with running it in the command window. However the primary issue is still occurring. What i meant by it runs is that the window opens as I have seen in examples however, it crashes seconds after doing so. I do not receive a error message. A large amount of text prints to the compiler window then it closes. this happens to quick for me to read any thing. Thank you for you time. Atlantis
What OS are you on? If on Windows, can you open an command prompt window and enter the javac command there? The window should stay open after the javac command ends and you'll be able to copy the Full text of the error message here.
To copy the contents of the command prompt window, click on icon at upperleft, select Edit and select Mark or Select All. Drag the white selection box over the text and then go back to the Edit menu and select Copy and then paste it in a file to be copied here.
I assumed you were running this from a command window. go to "start->run", then type "cmd" and click OK. you should get what is called a command window, or DOS window by us old-timers.
from here, cd into your directory where your .java file is. then run
and tell us the output.
Joined: Jul 23, 2008
Hello and thank you to all who helped. sorry for the confusion i was a bit frazzled at having tried so many things and nothing helping
Update: I was running it in the dos window. No matter the different things and paths I tried couldn't get it to run properly. On one computer (both pcs are running xp) I unistalled everything in the java folder and installed a older 5.0 version. I set the paths and got a simple program to compile and run the class file. Yay! On my other computer I also unistalled everything (though i had done this already) and reinstalled 6.7. set the paths and finally got it to compile using this command javac Desktop\MyFirstApp.java cant seem to run the the class file however. I get these errors even though ^I've tried different formats Exception in thread "main" java.lang.NoClassDefFoundError: Desktop\ va Caused by: java.lang.ClassNotFoundException: Desktop\MyFirstApp.jav at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Metho at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Sourc at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) not sure why when its the exact same code I used for the 5.0 which is a extremely simple one. but thats a chore for another day. Thanks again for your assistance. ^Atlantis^
if this complies your java file: javac Desktop\MyFirstApp.java
you would run this to execute your class file: java Desktop\MyFirstApp
Joined: Jul 23, 2008
Thanks for your quick responses. just thought I would update: I'll be working on this problem on this computer cause I would like to be able to run this version and I would hate to surrender when I'm sure I am doing something simple the wrong way. But thanks to my boyfriends assistance I have the older version running on another computer so I can continue studying. He placed the older version on it and got the paths right and gave me a working model to get the 6.7 to at least compile. He's a Mac tech and I have used his Mac to compile this same program but it will not run the .class file either. though I am not sure what version he is using either. His operating system is OS X but we have not altered anything to make it work was more a thing done out of curiosity. Getting things to run on this computer is now a side project and maybe someday I'll get things to run on his Mac. Anyways,I thought I would post the simple test program I found in a headfirst book that I am using:
This compiles and runs the class perfectly on 1.5. however the .class file does not run on the 6.7 version. It does compile without errors though. I am using the command java Desktop\MyFirstApp but I've also used every version i can think of this includes but is not limited to the entire path, different amounts of the path, and adding .class to the end of the file name. but I always receive the same error I posted earlier.
I have been through much of the board but can't seem to find this exact issue. Thanks for your ongoing help and speedy responses. ^A^
Go back to the Mac and type "javac -version" and "java -version" at the command line. Macs usually come with Java preinstalled, but it might not be the most recent version. If you compiled a .class file with Java5 it ought to execute easily with Java6 (but not vice versa).
Probably not a good idea to save everything to Desktop; it gets too cluttered. Make yourself a java folder somewhere, maybe C:\, maybe My Documents. Move all the .java files from desktop to that folder.
When you open the command prompt it usually points to My Documents (on Windows), so if you have "java" in "My Documents" you write cd java and it should say C:\Documents And Settings\Atlantis\My Documents\java:> or similar. Save your .java files in that directory, then when you give the "dir" command you ought to find them.
Test the java installation with javac -version, java -version, and you ought to get replies including 1.6.0_07, not "javac is not recognized as . . ."
Compile your .java files with "javac MyFirstApp.java" (assuming you don't have a package statement) and you can tell when it has worked because nothing happens. You should find evidence of the .class file with the "dir" command. Execute your compiled files with "java MyFirstApp" Don't write .java or .class.
Please use code tags when quoting code; I have added them so you can see how much easier the code is to read.