• 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

WeakHashMap error?

 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
u can just use java.util.HashMap or HashTable to handle such thing
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic