• 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

Help needed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic