Page 1 of 2 12 LastLast
Results 1 to 20 of 23
  1. #1
    Jacob1028555 is offline Member
    Join Date
    Jun 2011
    Posts
    20
    Rep Power
    0

    Default 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:
    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
    PLEASE HELP!!!!!!!!!!!!!!!!!!!

  2. #2
    Jacob1028555 is offline Member
    Join Date
    Jun 2011
    Posts
    20
    Rep Power
    0

    Default

    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");
    	}
    }

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,582
    Rep Power
    23

    Default

    Are you defining an interface or a class?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,002
    Blog Entries
    7
    Rep Power
    20

    Default

    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,

    Jos
    Last edited by JosAH; 06-05-2011 at 05:39 PM. Reason: too slow again ;-)
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Jacob1028555 is offline Member
    Join Date
    Jun 2011
    Posts
    20
    Rep Power
    0

    Default

    Thanks, but I changed it from interface, to class and a new problem arose:
    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 {
    in the class:
    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();
    	}
    }
    Sorry, I am rather new at the RMI stuff.
    Last edited by Jacob1028555; 06-06-2011 at 04:39 PM. Reason: Wrong Class Code

  6. #6
    Jacob1028555 is offline Member
    Join Date
    Jun 2011
    Posts
    20
    Rep Power
    0

    Default


  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,582
    Rep Power
    23

    Default

    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.

  8. #8
    Jacob1028555 is offline Member
    Join Date
    Jun 2011
    Posts
    20
    Rep Power
    0

    Default

    Whaa???? [JosAH: huge image removed]
    Last edited by JosAH; 06-06-2011 at 09:23 PM. Reason: big, huge, silly image removed

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,582
    Rep Power
    23

    Default

    Go back to your tutorial or text and read about how to use an interface.

  10. #10
    Jacob1028555 is offline Member
    Join Date
    Jun 2011
    Posts
    20
    Rep Power
    0

    Default

    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.

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,582
    Rep Power
    23

    Default

    Go back and read the error messge text:
    does not override abstract method actionPerformed
    That tells you what is wrong. Your code does not override a method in the interface.

    There is also google. Try googling this: java class implements interface

  12. #12
    Jacob1028555 is offline Member
    Join Date
    Jun 2011
    Posts
    20
    Rep Power
    0

    Default

    Should I use the @Override Annotation then???
    Last edited by Jacob1028555; 06-06-2011 at 09:56 PM.

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,582
    Rep Power
    23

    Default

    @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.

  14. #14
    Jacob1028555 is offline Member
    Join Date
    Jun 2011
    Posts
    20
    Rep Power
    0

    Default

    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!!!!!!!!!

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,582
    Rep Power
    23

    Default

    the only method there was actionPreformed(ActionEvent)
    ReRead the error message:
    does not override abstract method actionPerformed
    Look at it letter by letter.

  16. #16
    Jacob1028555 is offline Member
    Join Date
    Jun 2011
    Posts
    20
    Rep Power
    0

    Default

    Please!! Enough with the cryptic messages. Just tell me what I did wrong, so I don't do it again!!

  17. #17
    Jacob1028555 is offline Member
    Join Date
    Jun 2011
    Posts
    20
    Rep Power
    0

    Default

    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.

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,582
    Rep Power
    23

    Default

    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?

  19. #19
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,582
    Rep Power
    23

    Default

    Did you use the @Override statement in front of your listener method?
    What did it say?

  20. #20
    Jacob1028555 is offline Member
    Join Date
    Jun 2011
    Posts
    20
    Rep Power
    0

    Default

    Thank You for your time and Effort. I really am trying to learn. and I appreciate your help.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 03-27-2011, 05:49 AM
  2. the compile time error is below
    By nicholil in forum New To Java
    Replies: 2
    Last Post: 11-07-2010, 01:52 AM
  3. Compile error in Driver class, help plz
    By Battlefeldt in forum New To Java
    Replies: 3
    Last Post: 11-25-2009, 11:30 PM
  4. Java 1.5 compile time error
    By ank_k in forum New To Java
    Replies: 4
    Last Post: 11-13-2008, 11:12 AM
  5. Help with Compile time errors
    By bri1547 in forum New To Java
    Replies: 2
    Last Post: 08-24-2008, 11:22 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •