# Rmi ClassCastException $Proxy0 cannot be cast



## k40t1x (8. Dez 2007)

Hallo,

ich habe lange im google gesucht aber nix gefunden ich kriege diese exception

Exception in thread "main" java.lang.ClassCastException: $Proxy0 cannot be cast to mypackage.VoteServer
	at mypackage.Client.main(Client.java:11)


```
public interface VoteServer {
	public void vote(Integer party);
	public List<Integer> currentStandings();
}

public class VoteServerImp extends UnicastRemoteObject implements VoteServer {
	
	public List<Integer> ServerList = new ArrayList<Integer>(9);
	
	public VoteServerImp() throws java.rmi.RemoteException
	{
	}	

	public void vote(Integer party){
		int i = ServerList.get(party);
		i++;
		ServerList.set(party, i);
	}

	public List<Integer> currentStandings(){
		return ServerList;
		
	}
	
	public static void main(String args[])
	{
		try
		{
			VoteServer server1;

			server1 = new VoteServerImp();

			java.rmi.Naming.rebind("server1",(Remote) server1);


		}
		catch(Exception ex){}

	}

public class Client {

	public static void main(String args[]) throws Exception {
			VoteServer serv = (VoteServer)Naming.lookup("rmi://localhost/server1");
			serv.vote(2);
			System.out.println("2nd voted " + serv.currentStandings().get(2));
			System.out.println("1se not voted "+ serv.currentStandings().get(1));

               }
	
}
```

Danke im Voraus


----------



## semi (8. Dez 2007)

Das Interface muss Remote erweitern.
	
	
	
	





```
interface VoteServer extends Remote
{
   void vote(Integer party) throws RemoteException; 
   List<Integer> currentStandings() throws RemoteException;   
}
```


----------



## Gast (1. Feb 2008)

Die Erweiterung mit java.rmi.Remote ist wichtig und wird oft vergessen.


----------

