aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes WeakHashMap error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "WeakHashMap error?" Watch "WeakHashMap error?" New topic
Author

WeakHashMap error?

Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Hi Guys, the following class when complied is giving error that WeakHashMap class is not found. Can't we just use WeakHashMap like all other util classes?

The error is as follows:

C:\Documents and Settings\Lalitha\Desktop\Satti\Tenkai\Computer\Java\SCJD\CodeHelp\someThing.java:3: cannot access WeakHashMap
bad class file: .\WeakHashMap.java
file does not contain class WeakHashMap
Please remove or make sure it appears in the correct subdirectory of the classpath.
WeakHashMap map;
^
1 error
Tool completed with exit code 1

Can anyone please tell me the reason why its not compiling? Appreciate it. Thanks.
Javini Javono
Ranch Hand

Joined: Dec 03, 2003
Posts: 286
Hi,
I'll speculate:
bad class file: .\WeakHashMap.java

it looks like it is looking for WeakHashMap in your default path
(that is what the '.' means, I think).
I'd rename the class to the standard convention: beginning with
a capital letter, to make sure it is even finding the class you are writing.
Also, see if it can find Vector, ArrayList, and the like, as well, as I doubt
it is related only to the WeakHashMap concrete class in java.util.*.
Thanks,
Javini Javono
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Sorry. I forgot to mention before. Its working for all java.util classes except WeakHashMap.
Any idea? Thanks.
Javini, I changed it into standard convention. But before that also its working for all other java.util classes.
Billy Tsai
Ranch Hand

Joined: May 23, 2003
Posts: 1304
why are u using weakhashmap?
just use a hashtable or HashMap
also HashTable is synchronized even though it is slower than HashMap but u can argue that the speed of the mordern computer won't make too much difference


BEA 8.1 Certified Administrator, IBM Certified Solution Developer For XML 1.1 and Related Technologies, SCJP, SCWCD, SCBCD, SCDJWS, SCJD, SCEA,
Oracle Certified Master Java EE 5 Enterprise Architect
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
I want to use WeakHashMap to store locked records so that it can be used for client crashes. But its not working
Guys, any idea?
Don Wood
Ranch Hand

Joined: Dec 05, 2003
Posts: 65
Hi Satish,
There's not enough information in the post for me to be sure but judging from the error message, .bad class file: .\WeakHashMap.java, it looks to me like the name of the file is WeakHashMap.java but the name of the public class is different (someThing).
If this is indeed the problem, you need to use a different file name since you should not have a class the same name as one in the sdk. Whatever the file name is the public class or interface name must exactly match
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Hi Don
Originally posted by Don Wood:
Hi Satish,
There's not enough information in the post for me to be sure but judging from the error message, .bad class file: .\WeakHashMap.java, it looks to me like the name of the file is WeakHashMap.java but the name of the public class is different (someThing).

The whole class is that only. I just wrote if for testing purposes. And the error posted is the whole error.

If this is indeed the problem, you need to use a different file name since you should not have a class the same name as one in the sdk. Whatever the file name is the public class or interface name must exactly match
Really, I just laughed out for sometime when reading this. Sorry about that. Yeah, I know that we should not use any class names that match with SDK. I know you just want me to make sure that whether am sticking for this rule. Thanks for the concern.

Any idea now?
Don Wood
Ranch Hand

Joined: Dec 05, 2003
Posts: 65
Glad you got the humor.
Now, the name of the file is someThing.java because that is the name of the public class. Is that the file name you are using?
I put your four lines in a file by this name and it compiles fine. If your file name is correct then I'm stumped too.
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
All other java.util classes are working except this. You think I need to download JDK again if anything got wrong before. I have a couple of versions starting from 1.3

Error:

C:\Documents and Settings\Lalitha\Desktop\Satti\Tenkai\Computer\Java\SCJD\CodeHelp\WeakHashMapTest.java:4: cannot access WeakHashMap
bad class file: .\WeakHashMap.java
file does not contain class WeakHashMap
Please remove or make sure it appears in the correct subdirectory of the classpath.
WeakHashMap map;
^
1 error
Tool completed with exit code 1

Anyway, I will try my luck downloading JDK one more time. Want to use WeakHashMap for the purpose of handling client crashes. If this does'nt work am also thinking on a different approach using WeakReference.
Thanks.
Billy Tsai
Ranch Hand

Joined: May 23, 2003
Posts: 1304
u can just use java.util.HashMap or HashTable to handle such thing
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Originally posted by Billy Tsai:
u can just use java.util.HashMap or HashTable to handle such thing

Thanks Billy. I will try to use them and sort out the issue. I just want to go the traditional way of knowing when the client crashed by using WeakHashMap, but now I have to find a different way out of doing this.
Ah man! Why did I ever want to implement client crashes. Was just feeling a bit relieved today that got some sort of solution for graceful server shutdown(I am thinking its one way handling, don't know if its right ) and here is another issue.
Anyway thanks guys. I will try another way of dealing this. If anyone find out why its giving such error, please let me know. Thanks.
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Originally posted by Billy Tsai:
u can just use java.util.HashMap or HashTable to handle such thing

Hashtable is a legacy collection. There is not a single good reason to use it. Stick to the Collections Framework for resusability. If you need a synchronized collection, you can always use a factory method to make a synchronized Map.
Javini Javono
Ranch Hand

Joined: Dec 03, 2003
Posts: 286
Hi,
Only guessing, not having all the info; but, move everything that you
are working on into a separate directory or package.
package test1;
import java.util.*;
public class WeakHashMapTest {
WeakHashMap map;
}
Then compile
javac test1/*.java
and see what happens. That is, isolate the code completely and see what happens,
is my idea.
Thanks,
Javini Javono
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Hi Satish,
The only reasons this might be happening, that I can think of, are
1. You're not spelling(or capitializing) the name of the class correctly. Are you sure you're using [b]WeakHashMap[\b]? try copy/paste, just to be sure.
2. There's something wrong with your jdk install. Try running the following

All best,
M


Java Regular Expressions
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Javini, Max & others thanks for your replies.
I want to say to all of you: My sincere apologies to all of you. Its my mistake. The reason was I named another class WeakHashMap which deals with client crashing. I kept the name because I also had another client crashing sample called WeakReference. I was using both of these classes only for getting ideas. Those are not working code and I never compiled. So all the confusion was because of that class name. I named the classes like that to differentiate the client crashing technique, but guess its created a big havoc and I disturbed all of you. Am very very sorry guys. Will not repeat this again. You guys are great. Thanks a lot.
Ricardo Estafan
Ranch Hand

Joined: Mar 29, 2004
Posts: 84
Hello just a question can you deal with client crashes when you have the assignment where you have to return long lockCookie, so you cannot pass reference of client then can you? Could someone of you please explain me how to do this if you have this assignment with the long lockcookie?
Don Wood
Ranch Hand

Joined: Dec 05, 2003
Posts: 65

If this is indeed the problem, you need to use a different file name since you should not have a class the same name as one in the sdk. Whatever the file name is the public class or interface name must exactly match
Really, I just laughed out for sometime when reading this. Sorry about that. Yeah, I know that we should not use any class names that match with SDK. I know you just want me to make sure that whether am sticking for this rule. Thanks for the concern.

So you laughed about my comment not to use sdk supplied names and that turned out to be the problem? Hmmmmm.
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Hey Don, Sorry man
Originally posted by Don Wood:

So you laughed about my comment not to use sdk supplied names and that turned out to be the problem? Hmmmmm.

I used the names of the classes to differentiate the ways of dealing client crashes. As there was pseudo-code I never complied right...so I thought there's nothing like that. You know, as we are approaching to the end of the project, pretty simple things seems to be way too complex and the result is havoc and confusion to me and all.
I wish others are not like me
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11462
    
  94

Hi Ricardo,
can you deal with client crashes when you have the assignment where you have to return long lockCookie, so you cannot pass reference of client then can you? Could someone of you please explain me how to do this if you have this assignment with the long lockcookie?

You still need to have a unique reference for the client, however you may not need it in the Data class itself.
Your server code can implement the Unreferenced interface, which means that when there are no more remote clients who have a reference to your code, then the unreferenced() method will be called. In this method you can do any cleaning up processing (such as removing locks owned by that client).
I deliberately have not described this in any great detail, so that you get a chance to think about this for yourself first .
Th Unreferenced solution is easier (IMHO) to implememt than a WeakReference solution when you are dealing with cookies. However since it is not releated to the topic of this post (the WeakHashMap error), I would recommend you open a new topic if you would like to discuss this further.
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: WeakHashMap error?