Forums Register Login

Just started learning Java.. Question

+Pie Number of slices to send: Send
Ok, so I just started to learn Java, and I picked up the book Head First. I wrote the intro source code which is called "Party.java" in a program called Jedit, which I downloaded. I then went to the javac terminal and went to the command tab and entered "javac Party.java". It is telling me that error: cannot read: Party.java 1 error. Do I have the java file in the wrong directory or something?
+Pie Number of slices to send: Send
ok figured out that i needed the directory /downloads/ in there. But its still giving me 1 error..
+Pie Number of slices to send: Send
What error?
+Pie Number of slices to send: Send
ok I just rewrote it and it was fixed... now I have hello.class file in my folder. I tryed running java hello and Exception in thread "main" java.lang.NoClassDefFoundError: hello
[Process exited - exit code 1] comes up... ??
+Pie Number of slices to send: Send
anyone have any idea??
+Pie Number of slices to send: Send
Hi sam,

Its a error caused when you do not set your CLASSPATH properly.while you use java command try directing your command to the correct location of your class

eg:

suppose your hello.class exists in X:\firstPrg\Hello.class and you are running your program from d:\ in the command prompt then

you should use
java -cp X:\firstPrg Hello
this would work.....

bye
+Pie Number of slices to send: Send
Im using Mac OS X so would it be the same?
+Pie Number of slices to send: Send
I entered

java -cp\java\MyFirstApp

Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)

where options include:
-client to select the "client" VM
-server to select the "server" VM
-jvm is a synonym for the "client" VM [deprecated]
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.

-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
[Process exited - exit code 1]

thats what came up..
+Pie Number of slices to send: Send
When using Terminal, are you in the directory that contains your file Hello.class?

I recently posted some beginning instructions for Mac in the Mac forum. See if these help.

(You should not have to worry about a classpath setting at this point.)
[ March 27, 2007: Message edited by: marc weber ]
+Pie Number of slices to send: Send
Hi sam,

The mistake that you've made is there should be a space between -cp and \jav.. but you have type it continously... java -cp\java\MyFirstApp

Like marc said.. try out working within the very same same directory where your class files also exist ..
+Pie Number of slices to send: Send
Hi Sam,

I think you're getting great help here, but I suspect that there's another problem too. Our bad! We didn't really want our readers to try to compile the class we show on page 3. We put a note at the bottom of the page indicating that, but you're not the first to miss that, so we're going to fix that page.

In the meantime, if you skip ahead to page 9, you can go ahead and type that class in, then let these guys help you out with whatever environment setup issues you have to work out. When you do type that class in, it'll also help to copy and paste that code into your question.

Any finally, hang in there! The setup issues you're dealing with are probably the hardest thing you'll have to do for the next couple hundred pages

hth,

Bert
+Pie Number of slices to send: Send
Wow, a first for me. I'm in a forum where you can actually interact w/ an author of a book that you're reading. This is truly mind-blowing! I'm delving into Head First Design Patterns, one of the most amazing books on programming that I've studied yet, and one that is opening up my eyes to true code reuse. Thanks, Bert Bates.
+Pie Number of slices to send: Send
Thanks Pete,

I'll tell Eric and Beth that you're enjoying the book.

Bert
Replace the word "snake" with "danger noodle" in all tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 921 times.
Similar Threads
Not sure if this the place??
Exception in thread "main"
Really simple answer probably...
Windows 'Party' Code Run Error
can't start compiler
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:09:43.