Results 1 to 20 of 23
- 06-05-2011, 04:26 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 20
- Rep Power
- 0
Implementation Class for RMI App, Compile-Time Error
When I try to compile my class for my RMI Implementation, called ServiceServerImpl, I get these two errors when I try to compile, here is the Shell:
PLEASE HELP!!!!!!!!!!!!!!!!!!!Java Code:[jacob@localhost Source]$ javac -d ../Classes *.java ServiceServerImpl.java:5: '{' expected public interface ServiceServerImpl extends UnicastRemoteObject implements ServiceServer { ^ ServiceServerImpl.java:8: <identifier> expected public ServiceServerImpl() throws RemoteException { ^ 2 errors




- 06-05-2011, 04:39 PM #2
Member
- Join Date
- Jun 2011
- Posts
- 20
- Rep Power
- 0
BTW, here is the class code:
Java Code:import java.rmi.*; import java.util.*; import java.rmi.server.*; public interface ServiceServerImpl extends UnicastRemoteObject implements ServiceServer { HashMap serviceList = new HashMap(); public ServiceServerImpl() throws RemoteException { setUpServices(); } public void setUpServices() { serviceList.put("Calculator Service", new CalculatorService()); serviceList.put("Alphabetizer Service", new AlphabetizerService()); serviceList.put("Text Editor Service", new TextEditorService()); serviceList.put("Visual Music Service", new VisualMusicService()); serviceList.put("Chatting Service", new ChattingService()); } public Object[ ] getServiceList() { System.out.println("In Remote"); return serviceList.keySet().toArray(); } public Service getService(Object serviceKey) throws RemoteException { Service theService = (Service) serviceList.get(serviceKey); return theService; } public static void main(String args[ ]) { try { Naming.rebind("ServiceServer", new ServiceServerImpl()); } catch(Exception ex) { ex.printStackTrace(); } System.out.println("Remote Service Is Running"); } }
- 06-05-2011, 05:36 PM #3
Are you defining an interface or a class?
- 06-05-2011, 05:38 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,605
- Blog Entries
- 7
- Rep Power
- 17
An interface doesn't implement anything; it can just extend other interfaces. b.t.w. the code you showed us is a class definition, not an interface.
kind regards,
JosLast edited by JosAH; 06-05-2011 at 05:39 PM. Reason: too slow again ;-)
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-06-2011, 04:37 PM #5
Member
- Join Date
- Jun 2011
- Posts
- 20
- Rep Power
- 0
Thanks, but I changed it from interface, to class and a new problem arose:
in the class:Java Code:[jacob@localhost Source]$ javac -d ../Classes *.java ServiceBrowser.java:62: ServiceBrowser.MyListListener is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener class MyListListener implements ActionListener {
Sorry, I am rather new at the RMI stuff.Java Code:import java.awt.*; import java.rmi.*; import java.awt.event.*; import javax.swing.*; public class ServiceBrowser { Panel mainPanel; JComboBox serviceList; ServiceServer server; public void buildGui() { Frame frame = new Frame("Science Fair :: RMI Browser"); mainPanel = new Panel(); frame.add(BorderLayout.CENTER, mainPanel); Object[ ] services = getServicesList(); serviceList = new JComboBox(services); frame.add(BorderLayout.NORTH, serviceList); serviceList.addActionListener(new MyListListener()); frame.setSize(500, 500); frame.setVisible(true); } void loadService(Object serviceSelection) { try { Service svc = server.getService(serviceSelection); mainPanel.removeAll(); mainPanel.add(svc.getGuiPanel()); mainPanel.validate(); mainPanel.repaint(); } catch(Exception ex) { ex.printStackTrace(); } } Object[ ] getServicesList() { Object obj = null; Object[ ] services = null; try { obj = Naming.lookup("rmi://192.168.0.183/ServiceServer"); } catch(Exception ex) { ex.printStackTrace(); } server = (ServiceServer) obj; try { services = server.getServiceList(); } catch(Exception ex) { ex.printStackTrace(); } return services; } class MyListListener implements ActionListener { public void actionPreformed(ActionEvent ev) { Object selection = serviceList.getSelectedItem(); loadService(selection); } } public static void main(String[ ] args) { new ServiceBrowser().buildGui(); } }
Last edited by Jacob1028555; 06-06-2011 at 04:39 PM. Reason: Wrong Class Code
- 06-06-2011, 04:40 PM #6
Member
- Join Date
- Jun 2011
- Posts
- 20
- Rep Power
- 0









- 06-06-2011, 04:42 PM #7
Nothing to do with RMI.
Where is the MyListListener class definition? You don't show it.
When your class implements an interface, you are required to define all the methods defined in the interface.
Does your code do that? Read the API doc for the interface and get the specs on what methods it uses.
To check for spelling errors, put an @Override statement before the method definition.
- 06-06-2011, 05:10 PM #8
Member
- Join Date
- Jun 2011
- Posts
- 20
- Rep Power
- 0
Whaa???? [JosAH: huge image removed]
Last edited by JosAH; 06-06-2011 at 09:23 PM. Reason: big, huge, silly image removed
- 06-06-2011, 05:13 PM #9
Go back to your tutorial or text and read about how to use an interface.
- 06-06-2011, 09:04 PM #10
Member
- Join Date
- Jun 2011
- Posts
- 20
- Rep Power
- 0
My book that I learned out of, nor the tutorial I just read say anything about class definitions for interfaces.
I'm sorry to be such a stick in the mud.
.gif)
- 06-06-2011, 09:14 PM #11
Go back and read the error messge text:
That tells you what is wrong. Your code does not override a method in the interface.does not override abstract method actionPerformed
There is also google. Try googling this: java class implements interface
- 06-06-2011, 09:47 PM #12
Member
- Join Date
- Jun 2011
- Posts
- 20
- Rep Power
- 0
Should I use the @Override Annotation then???
Last edited by Jacob1028555; 06-06-2011 at 09:56 PM.
- 06-06-2011, 09:52 PM #13
@Override is a statement asking the compiler to check if the following method definition is indeed overriding a method.
Yes it is a good idea to use it. Before it was available, a simple typo of a method name could cost a lot of time finding out why a listener was not being called. That was mainly when using Adaptors which define all the methods with empty methods. When using an implements, the compiler will check for all required methods; As you see with your error.
- 06-06-2011, 10:00 PM #14
Member
- Join Date
- Jun 2011
- Posts
- 20
- Rep Power
- 0
Okay, I get that, but then what else is required there??
Sorry for being a pain in the butt, the book never said anything about this.
I checked the docs for ActionListener, and the only method there was actionPreformed(ActionEvent). And I checked the SuperInterface for it and it had no methods.
I AM CONFUSED!!!!!!!!!


- 06-06-2011, 10:07 PM #15
ReRead the error message:the only method there was actionPreformed(ActionEvent)
Look at it letter by letter.does not override abstract method actionPerformed
- 06-06-2011, 10:46 PM #16
Member
- Join Date
- Jun 2011
- Posts
- 20
- Rep Power
- 0
Please!! Enough with the cryptic messages. Just tell me what I did wrong, so I don't do it again!!







- 06-06-2011, 10:57 PM #17
Member
- Join Date
- Jun 2011
- Posts
- 20
- Rep Power
- 0
Sorry to be so rude in the last post. I am starting to get frustrated because the answer is right there, but I don't get it. Part of the problem is that i am teaching this to myself. From a book: Head First Java 2nd Edition.
- 06-06-2011, 11:00 PM #18
Sorry, you need to learn to look at your code and find your errors. I'm not going to tell you what is wrong. But I will tell you where to look. You'll need to learn to do things at this level of detail if you want to learn to program.
Did you look at what I pasted above? And compare it with the text of the error message? Letter by letter?
- 06-06-2011, 11:05 PM #19
Did you use the @Override statement in front of your listener method?
What did it say?
- 06-06-2011, 11:07 PM #20
Member
- Join Date
- Jun 2011
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
Eclipse Compile Error: Call validateValue(Class<T>, String, Object, Class<?>...)
By Tomshi in forum EclipseReplies: 0Last Post: 03-27-2011, 05:49 AM -
the compile time error is below
By nicholil in forum New To JavaReplies: 2Last Post: 11-07-2010, 01:52 AM -
Compile error in Driver class, help plz
By Battlefeldt in forum New To JavaReplies: 3Last Post: 11-25-2009, 11:30 PM -
Java 1.5 compile time error
By ank_k in forum New To JavaReplies: 4Last Post: 11-13-2008, 11:12 AM -
Help with Compile time errors
By bri1547 in forum New To JavaReplies: 2Last Post: 08-24-2008, 11:22 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks