It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K & B Chapter 9 Q 21 Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K & B Chapter 9 Q 21 Threads" Watch "K & B Chapter 9 Q 21 Threads" New topic
Author

K & B Chapter 9 Q 21 Threads

seemapanth Joshi
Ranch Hand

Joined: Nov 28, 2004
Posts: 47
The following compiles but does not run


The error message is

java.lang.NoSuchMethodError: Foo.doStuff()V
at Test12$1.run(Test12.java:23)
at java.lang.Thread.run(Unknown Source)


What did I do ...What did I do please help
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Joshi,

I copy paste your code to my machine and compiled it. No problem. Then I compared your code with the code from the K&B book as you mentioned.

So here is what you need to do:

1. take out the comment '//' from your f.doStuff() line.
2. change the line 'int x = 5' to 'int x = 10' and ou will get your notify.

or try this on your machine:



Regards,
Darya
[ February 19, 2005: Message edited by: Darya Akbari ]

SCJP, SCJD, SCWCD, SCBCD
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
I could not get your error message,

Your code compiled OK and hung when executed, as it should.


Mike Gershman
SCJP 1.4, SCWCD in process
seemapanth Joshi
Ranch Hand

Joined: Nov 28, 2004
Posts: 47
I am changing class name from



to


and all hell is breaking loose.

for 1st case I get error

1
2
Exception in thread "main" java.lang.NullPointerException
at Test.main(Test.java:6)


The scenario is the same in second case as mentioned in my previous post. i.e.
java.lang.NoSuchMethodError: Foo.doStuff()V
at Test12$1.run(Test12.java:7)
at java.lang.Thread.run(Unknown Source)
java.lang.NoSuchMethodError: Foo.doStuff()V
at Test12$2.run(Test12.java:13)

Thanks for looking it up but why is this happenning. Would greatly appreciate a little more light.
[ February 19, 2005: Message edited by: seemapanth Joshi ]
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Joshi,

simply copy paste my code to your machine and compile it and tell me what you get.

Regards,
Darya
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Hi Seemapanth,

Like others, I had no problem running your code on a DOS prompt. How did you set the CLASSPATH? Did you upgrade to other JDK version before this? Did you use an IDE to execute the code?

Joyce
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Here's how I did:
1. Copied your code into a file named Test12.java
2. After compiling, 4 files: Test12.class, Foo.class, Test12$1.class and Test12$2.class were generated.
3. c:\> java Test12

However, I could able to reproduce your problem by creating a separate Foo.java that looks like this:



Compile this Foo.java after step 2 such that it overrides the existing one Foo.class. Then run java Test12. I got the following runtime error:


[ February 22, 2005: Message edited by: Joyce Lee ]
seemapanth Joshi
Ranch Hand

Joined: Nov 28, 2004
Posts: 47
Whoa....I am sorry I had put it into "unresolved problem" section so went away from this forum to look at other problems related to scjp since my exam date is fast approaching. I am going to go back to my problem...clean the slate and try again ( with all your inputs )...then report back.

Greatly appreciate all the inputs. Hang on...It must be something very stupid I must have done but I have to get my finger on it.
seemapanth Joshi
Ranch Hand

Joined: Nov 28, 2004
Posts: 47
Joyce Lee,

you were right on target, my classpath did not include a "."

So there ...Everything under control and peaceful and heartfelt gratitude is in order for everybody. Thank you...Thank you... Thank you... all of you.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: K & B Chapter 9 Q 21 Threads