Jump to content
IGNORED

Java gurus


Guest theSun

Recommended Posts

So I wrote a bunch of code for a Java project, and I can get it to compile with the javac command, but whenever i try to run a script there's a bunch of "can't find class" errors. I'm assuming that this has something to do with my environment variables, but i have appended my java \lib directory in TEMP -> CLASSPATH and the \bin directory in TEMP -> Path. Here's the error. This is probably something really dumb but i can't figure it out :(

 

javaerror.jpg

Link to comment
Share on other sites

You can use the option -classpath instead of environment variables:

 

java -classpath <path of the directory where the class resides you want to run> <name of the class you want to run>

Link to comment
Share on other sites

i'm trying

 

java -classpath <C:\Program Files\Java\jdk1.6.0_16\Examples\Example 3> nameofscript.java

 

and it's saying it can't find the file? The example directories are my own, i'm positive that the syntax is as written.

 

sorry to be a bother but i don't want to waste class time with troubleshooting.

Link to comment
Share on other sites

yeah, -classpath should solve your problem. however, i strongly recommend, if you haven't yet, check out Eclipse IDE. it will make your life so much easier if you plan on coding any more java.

 

i'm trying

 

java -classpath <C:\Program Files\Java\jdk1.6.0_16\Examples\Example 3> nameofscript.java

 

and it's saying it can't find the file? The example directories are my own, i'm positive that the syntax is as written.

 

sorry to be a bother but i don't want to waste class time with troubleshooting.

get rid of the "<>" parentheses

Link to comment
Share on other sites

javaerror2.jpg

 

here's the same error... ???? Wtf am i doing wrong, this is my last college programming class and i can't even get the 2nd assignment to run grrrrrrrrrrrrrrrrrr

Link to comment
Share on other sites

yeah, put the file path in double quotes, like this:

 

java -classpath "C:\Program Files\Java\jdk1.6.0_16\Examples\Example 3" nameofscript.java

 

lol, also, you shouldn't be running a .java file, but a compiled, .class file instead!

Link to comment
Share on other sites

yeah you are right on the money. as you can see it cannot find "C:\Program Files\Java\jdk1.6.0_16\Examples\Example" not "C:\Program Files\Java\jdk1.6.0_16\Examples\Example 3", cmd.exe cannot read minds you have to pay attention to syntax, especially spaces, because thats one of the first things it looks for when separating arguments.

Link to comment
Share on other sites

okay, look. first, you gotta compile the .java (source) file, so you have a .class (binary) file. you do that with javac i presume.

 

then, you want to run your .class file in the java virtual machine. you do that with the "java" command. i think you must not use the ".class" extension though. just the classname. and classes' names should be capitalized.

Link to comment
Share on other sites

yeah the javaclasspath system is quite obscure, took me 4 hours to figure out how it works(then i coded in 30 minutes a htmlUnit thingy in order to deconnect/reconnect my internet whereas i did'nt know a single word of javascript.)

 

Sometimes computers are just computers.

 

Anyway, you've just fortgotten to add the current path (.) in your classpath.

i mean the thing you get from running pwd.

 

just try this:

java -classpath .;C:\Program Files\Java\jdk1.6.0_16\Examples\Example 3> nameofscript
Link to comment
Share on other sites

then, you want to run your .class file in the java virtual machine. you do that with the "java" command. i think you must not use the ".class" extension though. just the classname. and classes' names should be capitalized.

 

haha! should have paid attention in class. i got my env variable mess worked out after class today, and i can actually start testing my project! hooray!

 

thanks watmm.

 

edit - forgot to submit this before, but i just turned in the whole project. it's fun (lol) coding something without any way of testing, really makes you pay attention to syntax. only a few errors in my project, quickly corrected with watmm's help!

Link to comment
Share on other sites

i know what you mean. it really is kind of fun, but if you gotta get some work done, it's so much slower. if you use an IDE like Eclipse, code fies from your mind straight into the source. with all the autocomplete and template and navigation features. and it's so much more difficult to make an e.g. syntax error, because the compiler is checking your source on-the-fly and shows you what's wrong. really, try it!

 

though i do remember coding in notepad.exe or even on paper :) it was fun, but i wouldn't want to do it that way if i wanted to actually make something work.

 

glad you made it work!

Link to comment
Share on other sites

i'm going to get eclipse later today. for some reason i thought it wasn't free...

 

i don't really mind coding at the academic level, but i can't imagine writing complex programs (video games, AI, sensory programming, etc), i'd go crazy within a year.

Link to comment
Share on other sites

yeah java does not equal clean. although i don't know what language is. maybe some kind of assembly, or pure C, or even haskell? i guess it depends on how you define clean.

Link to comment
Share on other sites

yeah java does not equal clean. although i don't know what language is. maybe some kind of assembly, or pure C, or even haskell? i guess it depends on how you define clean.

 

Haskell is pretty clean to me, because of its mathematical underpinnings. But if that's of any use in the real world, I wouldn't know, I don't do real world.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.