Rmi ClassCastException $Proxy0 cannot be cast

Status
Nicht offen für weitere Antworten.

k40t1x

Neues Mitglied
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)

Code:
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

Top Contributor
Das Interface muss Remote erweitern.
Code:
interface VoteServer extends Remote
{
   void vote(Integer party) throws RemoteException; 
   List<Integer> currentStandings() throws RemoteException;   
}
 
G

Gast

Gast
Die Erweiterung mit java.rmi.Remote ist wichtig und wird oft vergessen.
 
Status
Nicht offen für weitere Antworten.

Ähnliche Java Themen

Neue Themen


Oben