aspose file tools*
The moose likes Beginning Java and the fly likes Java on 32 Bit Windows? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java on 32 Bit Windows?" Watch "Java on 32 Bit Windows?" New topic
Author

Java on 32 Bit Windows?

Greg Kim
Greenhorn

Joined: Jun 20, 2011
Posts: 5
I just started learning Java, and right now, my main problem is that I can't compile my code. I followed the directions here: http://www.coderanch.com/how-to/java/how-to-create-java-program. I downloaded the x86 JDK, and I set the environment variables. When I type java -version, it shows me the version number, but when I type javac -version, it says that javac is not recognized as a command. What could be the cause of the problem?
Daniel Marti
Ranch Hand

Joined: Jun 08, 2011
Posts: 37
That sounds like you didn't add the JDK folder to your PATH environment variables.

Please follow "Setting the JAVA_HOME and PATH environment variables" in the link you have on your post and then report back with any problems.
Wim Vanni
Ranch Hand

Joined: Apr 06, 2011
Posts: 96

Welcome to the ranch, Greg!
Greg Kim
Greenhorn

Joined: Jun 20, 2011
Posts: 5
I figured out what I did wrong. I made a user JAVA_HOME and a system PATH, but it's fixed now. My command prompt now recognizes the command, but I still can't compile the MooseGrettings.java example. Why is there an "src" in the file path in the example? Should I make a folder named src?
Wim Vanni
Ranch Hand

Joined: Apr 06, 2011
Posts: 96

'src' will typically denote the root-folder of your java-code, also referred to as the default package in IDE's like Eclipse. It sounds to me that you didn't follow the tutorial by the letter and ended up trying to copy/paste and execute the javac or java command line without referring to the exact location of the java-file.

May I suggest that whenever you encounter problems, you try to add the 'stacktrace' to your posts. This errorlog is definitely helpful for identifying the cause of your problems, although it takes some practice to read it and even for experienced coders it can be cryptic at times.

Wim
Greg Kim
Greenhorn

Joined: Jun 20, 2011
Posts: 5
I'm not sure what a stacktrace is, but I'm guessing this is it:

C:\Documents and Settings\TKim>java -classpath . MooseGreetings
Exception in thread "main" java.lang.NoClassDefFoundError: MooseGreetings
Caused by: java.lang.ClassNotFoundException: MooseGreetings
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: MooseGreetings. Program will exit.

EDIT: Oh, I understand what I did wrong here, but I'm not completely sure what I need to do.
Wim Vanni
Ranch Hand

Joined: Apr 06, 2011
Posts: 96

It's a bad habit to put your code 'on the desktop'. Try to reserve a specific folder like 'c:\java\src' (as the tutorial suggested).

Other than that: what do you think you did wrong?
Greg Kim
Greenhorn

Joined: Jun 20, 2011
Posts: 5
I put the file in the suggested folder. Correct me if I'm wrong, but I think I need to do something else. Right now, I'm trying to compile by starting with "goto C:\java\src>MooseGreetings.java". Then I just type "javac MooseGreetings.java".
Wim Vanni
Ranch Hand

Joined: Apr 06, 2011
Posts: 96

I'm not sure what you mean by 'goto c:\java ...'. Hopefully that's using 'cd c:\java\src' at the command prompt as the tutorials suggests

If you have the command prompt open and it shows you you are indeed in that folder (c:\java\src) and if you then type the javac command, you still get an error?

Or is it at the point where you do 'java -classpath ...'?


BTW that was indeed what I was referring to as a stacktrace.
Greg Kim
Greenhorn

Joined: Jun 20, 2011
Posts: 5
I got it working, thanks for the help.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
Well done

What was the actual problem which you corrected?
Andrew Kenyon
Greenhorn

Joined: Dec 23, 2010
Posts: 5
Since it appears the OP's problem has been resolved, I hope I can hop into this thread with what I think is a similar problem without anyone thinking that I'm hijacking the thread.

I signed up at at a website that that provides programming katas for self-development (I won't say which, because I don't want this post removed), but when tried to compile the "Hello World" solution I got back some errors, so thinking that I would just rewrite the solution in a way that I (think I) know should work, it still wouldn't compile. The code I used was:



For sanity's sake, I just now compiled and ran it in [whatever IDE I'm using], and it worked fine. But when I try to do it from the command line, the compiler gives me:

Exception in thread "main" java.lang.NoClassDefFoundError: Mykata
Caused by: java.lang.ClassNotFoundException: Mykata
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: Mykata. Program will exit.


Could this be because I installed the kata subdirectories from my /home/Andrew folder? I thought that once I had installed the JDK, that I could compile and run files.java from any directory. I don't have any problems compiling and running programs from my /home/Andrew/hfjava directory.

Any thoughts?
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
Andrew Kenyon wrote:


For sanity's sake, I just now compiled and ran it in [whatever IDE I'm using], and it worked fine. But when I try to do it from the command line, the compiler gives me:

Exception in thread "main" java.lang.NoClassDefFoundError: Mykata
Caused by: java.lang.ClassNotFoundException: Mykata

Any thoughts?


Mykata =/= MyKata. You need to capitalize the K.


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java on 32 Bit Windows?