| Author |
Help needed
|
Al Dodd
Greenhorn
Joined: Feb 08, 2008
Posts: 7
|
|
For my degree project I am trying to write a simple messaging system for the shift I supervise at work to communicate outside of work across the internet. It will display a shift rota for the day and also they can send messages to each other, asynchronously. However i am failing miserably to code it. It is suppose to work on RMI The message system has three classes, message, messageOperator, messageOperatorHolder and an interface MessageOperatorInterface This is the code for message An this is the code for messageOperator And then this is the messageOperatorHolder When I compile it I get cannot use non-static method to reference static context. I know this means that I am referencing the class messageOperator rather than an instance. But I need a system that will allow me to create messageOperators. A little help? will need help the server in future if any one has got the time? Regards Al
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32674
|
|
Originally posted by Al Dodd: When I compile it I get cannot use non-static method to reference static context.
More of a beginner's question if you are getting THAT error message. Why are you using HashTable and Enumeration rather than more modern classes? Why have you got a void getMessages() method? Why are you not calling your classes by the correct names starting with a Capital Letter? Then you would realise that you are calling instance methods on the name of their type (the class name) rather than on the name of an object.
|
 |
Eric Weinberg
Greenhorn
Joined: Nov 11, 2004
Posts: 18
|
|
Just to reinforce what Campbell Ritchie said, check out number 10 of Top Ten Errors Java Programmers Make Just ignore number 6 as it's completely wrong (the author of the faq never read Pass-by-Value Please [ June 03, 2008: Message edited by: Eric Weinberg ]
|
 |
Al Dodd
Greenhorn
Joined: Feb 08, 2008
Posts: 7
|
|
Okay I take on board the comment on coding convention and will change it and I am sorry for posting in the wrong forum! What modern class would you suggest I use? I already new why I was getting the non-static error but thanks for pointing out the FAQs, One of them answered another question I had. Regards Al
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32674
|
|
Modern classes? HashMap and Iterator. And declare your Map like this:- private Map<Integer, Message> messOp; . . . messOp = new HashMap<Integer, Message>(); Don't make the Map public. If you are using integer numbers as keys for messages, why don't you use a List and use get(int) to get the message? [edit]I have worked out why you aren't using a List.[/edit] [ June 03, 2008: Message edited by: Campbell Ritchie ]
|
 |
 |
|
|
subject: Help needed
|
|
|