Results 1 to 10 of 10
  1. #1
    arcelivez is offline Member
    Join Date
    Apr 2011
    Posts
    12
    Rep Power
    0

    Default JAVA RMI - Can't create server, because casting to it's interface doesn't work?

    Hi

    well I have a method in my client, where I am trying to create the server instance using the my inteface RemInterface which is the extension of Remote interface. The interface RemInterface is in the same package. But it just doesn't cast. :S it offers me to import <currentpackagename>.RemInterface But it's not necessary to import it since it's there automatically cause it's in the same package and also this works fine RemInterface myServer = null;

    So what could be the real problem of this?

    Here it is:

    Java Code:
    private void showGUI() {
            //Create and set up the window.
            JFrame window = new JFrame("Shared Whiteboard Client");
            window.setPreferredSize(new Dimension(450, 300));
            window.setResizable(false);
            window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            MainWindow crazy = new MainWindow();
            crazy.addComponents(window.getContentPane());
    
            // Java RMI part
            String url = "//127.0.0.1/WhiteboardServer";
            RemInterface myServer = null;
            
    
            // Here is my problem:
            myServer = new (RemInterface)Naming.lookup(url);
            
            
    
            //Display the window.        
            window.pack();
            window.setLocationRelativeTo(null);
            window.setVisible(true);
        }
    If I try to compile, I get the error, which is exactly that line I've been talking about - myServer = new (RemInterface)Naming.lookup(url);
    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - Erroneous ctor sym type: <any>
    	at whiteboardclientrmi.MainWindow.showGUI(MainWindow.java:51)
    	at whiteboardclientrmi.MainWindow.access$400(MainWindow.java:25)
    	at whiteboardclientrmi.MainWindow$5.run(MainWindow.java:154)
    	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:646)
    	at java.awt.EventQueue.access$000(EventQueue.java:84)
    	at java.awt.EventQueue$1.run(EventQueue.java:607)
    	at java.awt.EventQueue$1.run(EventQueue.java:605)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:616)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    BUILD SUCCESSFUL (total time: 5 seconds)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?

    Uncompilable source code
    What happens when you try to compile the source using the javac command?

    Try separating that compound statement into simple, single statements and printing out the results of each step.

  3. #3
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?

    Java Code:
    myServer = new (RemInterface)Naming.lookup(url);
    Why are you calling new?

  4. #4
    arcelivez is offline Member
    Join Date
    Apr 2011
    Posts
    12
    Rep Power
    0

    Default Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?

    ;D Thanks indeed you were right, it solved the problem.
    But still I now have a different problem, it says:
    Java Code:
    Exception in thread "AWT-EventQueue-0" java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
    	at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
    	at java.security.AccessController.checkPermission(AccessController.java:546)
    	at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
    	at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)
    	at java.net.Socket.connect(Socket.java:524)
    	at java.net.Socket.connect(Socket.java:478)
    	at java.net.Socket.<init>(Socket.java:375)
    	at java.net.Socket.<init>(Socket.java:189)
    	at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
    	at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
    	at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
    	at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
    	at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
    	at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
    	at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    	at java.rmi.Naming.lookup(Naming.java:84)
    	at whiteboardclientrmi.MainWindow.showGUI(MainWindow.java:51)
    	at whiteboardclientrmi.MainWindow.access$400(MainWindow.java:22)
    	at whiteboardclientrmi.MainWindow$5.run(MainWindow.java:163)
    	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:646)
    	at java.awt.EventQueue.access$000(EventQueue.java:84)
    	at java.awt.EventQueue$1.run(EventQueue.java:607)
    	at java.awt.EventQueue$1.run(EventQueue.java:605)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:616)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    And the client method currently looks like this:
    Java Code:
     private void showGUI() {
            //Create and set up the window.
            JFrame window = new JFrame("Shared Whiteboard Client");
            window.setPreferredSize(new Dimension(450, 300));
            window.setResizable(false);
            window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            MainWindow crazy = new MainWindow();
            crazy.addComponents(window.getContentPane());
    
            // Java RMI part
            if (System.getSecurityManager() == null) {
                System.setSecurityManager(new RMISecurityManager());
            }
            String url = "//127.0.0.1/WhiteboardServer";
            RemInterface myServer = null;
            try {
                myServer = (RemInterface)Naming.lookup(url);
            } catch (NotBoundException ex) {
                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
            } catch (MalformedURLException ex) {
                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
            } catch (RemoteException ex) {
                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
            }
            
    
    
            //Display the window.        
            window.pack();
            window.setLocationRelativeTo(null);
            window.setVisible(true);
        }

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?

    java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
    Now you need to give your code permission. How are you executing the code that gets this exception?

  6. #6
    arcelivez is offline Member
    Join Date
    Apr 2011
    Posts
    12
    Rep Power
    0

    Default Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?

    Quote Originally Posted by Norm View Post
    Now you need to give your code permission. How are you executing the code that gets this exception?
    How can I do that?
    I'm executing everything using Netbeans...

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?

    Sorry, I don't know anything about how to use your IDE.

  8. #8
    arcelivez is offline Member
    Join Date
    Apr 2011
    Posts
    12
    Rep Power
    0

    Default Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?

    Quote Originally Posted by Norm View Post
    Sorry, I don't know anything about how to use your IDE.
    Can you tell me how it can be compiled and run and security enabled in command line maybe? I'm using linux ubuntu 11.10 64 bit

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?


  10. #10
    arcelivez is offline Member
    Join Date
    Apr 2011
    Posts
    12
    Rep Power
    0

    Default Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?

    Alright, thanks for your help. ;)

Similar Threads

  1. Trying to create simple Timer, doesn't work
    By Ragoune in forum New To Java
    Replies: 4
    Last Post: 07-06-2011, 09:24 PM
  2. Replies: 10
    Last Post: 06-26-2011, 01:07 AM
  3. webstart link some time doesn't work after Java upgrade
    By Richard Gillespie in forum Advanced Java
    Replies: 0
    Last Post: 12-21-2010, 04:01 PM
  4. Replies: 0
    Last Post: 12-21-2010, 03:21 PM
  5. Java server listening on given interface?
    By Joe2003 in forum Advanced Java
    Replies: 2
    Last Post: 01-26-2009, 05:14 PM

Posting Permissions

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