• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java on 32 Bit Windows?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just started learning Java, and right now, my main problem is that I can't compile my code. I followed the directions here: https://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?
 
Ranch Hand
Posts: 37
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 96
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the ranch, Greg!
 
Greg Kim
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 96
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 96
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 96
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it working, thanks for the help.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done

What was the actual problem which you corrected?
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 710
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic