# RemoteException wieso ?



## Shakal (22. Okt 2013)

hey leute ich bekomme eine RemoteException und ich habe echt kein plan warum

```
Fehler beim Lesen vom Server: null
Fehler beim Lesen vom Server: null
java.rmi.RemoteException
	at Client.getText(Client.java:58)
	at ClientThread.run(ClientThread.java:44)
```
das ist client 58


```
public String getText() throws RemoteException{
		try{
			return server.getText();
		}
		catch(Exception e){
			System.out.println("Fehler beim Lesen vom Server: " + e.getMessage());
			throw new RemoteException(e.getMessage());
		}
	}
```
Server ist implementiert mein Remote Interface


```
public class Server extends UnicastRemoteObject implements RMIServer{
...
	public String getText(){
		return data.getTextFeld();
	}
}
```

und in data speicher ich die Nachrichten

```
public class Daten extends Observable implements Serializable{
...
	public String getTextFeld() {
		return textFeld;
	}
}
```


----------



## KSG9|sebastian (25. Okt 2013)

Da du die eigentliche Exception einfach verwirfst kann dir wohl keiner helfen..


```
public String getText() throws RemoteException{
        try{
            return server.getText();
        }
        catch(Exception e){
           [b]Das ist übel!![/b]
            System.out.println("Fehler beim Lesen vom Server: " + e.getMessage());
            throw new RemoteException(e.getMessage());
        }
    }
```

Zumindest solltest du die Exception loggen, darin wird vermutlich auch stehen woran das Problem liegt!

** Edith **
Du leitest von Observable ab, welche nicht serialisierbar ist. Jenachdem was im Observable steckt wirst du wohl ne NotSerializableException bekommen


----------



## Shakal (19. Jan 2014)

Ich habe auch dieses Problem und keine Ahnung warum 
Client 

```
public ServerInterface connect(ServerInterface serv, MetaWindow fenster,
			ServerVerbinden servCon) {
		this.fenster = fenster;
		this.servCon = servCon;
		this.server = serv;
		try {
			String adress = "rmi://localhost/MetaServer";
			server = (ServerInterface) Naming.lookup(adress);
			server.istVerbunden(servCon.getTfUserName(),this);
			return serv;
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (RemoteException e) {			
			JOptionPane.showMessageDialog(null,
                "Es konnte keine Verbindung zum Server hergestellt werden(Remote)",
                "Verbindungsfehler",					      
                JOptionPane.WARNING_MESSAGE);
		} catch (NotBoundException e) {            
			JOptionPane.showMessageDialog(null,
                "Es konnte keine Verbindung zum Server hergestellt werden(NotBound)",
                "Verbindungsfehler",					      
                JOptionPane.WARNING_MESSAGE);
		}
		return serv;

	}
```

Server 

```
public void run() {
		try{
			rmiRegistry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
			serv = new ServerImpl(sp);
			adress = "rmi://"+sp.getIp()+"/MetaServer";
			Naming.rebind(adress , serv);
			sp.setSystemText(sp.getSystemFeld().getText()+"Server gestartet...\n\r");
			
		}catch(Exception e){
			sp.setSystemText(sp.getSystemFeld().getText()+e.getMessage());
		}
	}
```

Bei BEIDEN gebe ich localhost ein ... also leutet die addresse bei beiden rmi://localhost/MetaServer


----------



## Sen-Mithrarin (19. Jan 2014)

warum ist das denn immer so schwer ....


Throwable.printStackTrace() !!!!! das gehört IMMER ! in einen catch-block


----------



## Shakal (19. Jan 2014)

Das sagt er mit der Throwable ... und lese ich da richtig das er ServerInterface nicht findne kann 


```
java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
	java.lang.ClassNotFoundException: Server.ServerInterface
	at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
	at java.rmi.Naming.lookup(Unknown Source)
	at Client.connect(Client.java:173)
	at Controller.actionPerformed(Controller.java:82)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$200(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: Server.ServerInterface
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.rmi.server.LoaderHandler$Loader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at sun.rmi.server.LoaderHandler.loadClassForName(Unknown Source)
	at sun.rmi.server.LoaderHandler.loadProxyInterfaces(Unknown Source)
	at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
	at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
	at java.rmi.server.RMIClassLoader$2.loadProxyClass(Unknown Source)
	at java.rmi.server.RMIClassLoader.loadProxyClass(Unknown Source)
	at sun.rmi.server.MarshalInputStream.resolveProxyClass(Unknown Source)
	at java.io.ObjectInputStream.readProxyDesc(Unknown Source)
	at java.io.ObjectInputStream.readClassDesc(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.readObject(Unknown Source)
	... 40 more
```


----------



## Sen-Mithrarin (19. Jan 2014)

ach guck mal an : ClassNotFound ... jetzt wird so einiges klar ...


auf gut glück : du hast zwei packages : server und client ... und versuchst im client irgendwas auf eine klasse im server zu casten > not found ... sollte nich mal compilen ...


das thema gabs hier schon so oft : das interface auf das gecastet wird in ein eigenes common-package auf das beide seiten zugreifen können ...


----------



## Shakal (20. Jan 2014)

Jo danke hat geklappt !:toll:


----------

