Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 爪哇RMI doenst“;请转到";界面功能_Java_Rmi - Fatal编程技术网

Java 爪哇RMI doenst“;请转到";界面功能

Java 爪哇RMI doenst“;请转到";界面功能,java,rmi,Java,Rmi,您好,我正在尝试创建一个RMI程序,从服务器发送和接收数据。然而,在我创建注册表并查找它们之后,我的程序指向接口中的一个方法,它将自己放入一个integerpage(通过调试器)。我的代码如下 为客户 对于服务器 接口 公共接口TestRemote扩展远程{ public ArrayList getOpdata()引发RemoteException; public void SendMyData(整数分数,字符串播放器)引发RemoteException;} 对于接口实现: p

您好,我正在尝试创建一个RMI程序,从服务器发送和接收数据。然而,在我创建注册表并查找它们之后,我的程序指向接口中的一个方法,它将自己放入一个integerpage(通过调试器)。我的代码如下

为客户 对于服务器 接口
公共接口TestRemote扩展远程{
public ArrayList getOpdata()引发RemoteException;
public void SendMyData(整数分数,字符串播放器)引发RemoteException;}
对于接口实现:

        private static final long serialVersionUID = 1L;
    private ArrayList<TempPlayer> opdata = new ArrayList<TempPlayer>();
    private ArrayList<String> lobbydata = new ArrayList<String>();
    protected RemoteImp() throws RemoteException
    {

    }
    @Override
    public ArrayList<TempPlayer> getOpdata() throws RemoteException {
        return  opdata;
    }

    @Override
    public void SendMyData(int score, String name) throws RemoteException {
        //opdata.add(String.valueOf(score));

        for (TempPlayer player : opdata) {
            if (player.player == name) {
                player.setScore(score);
            } else {
                opdata.add(new TempPlayer(score, name));
            }
        }  
    }
}
private static final long serialVersionUID=1L;
private ArrayList opdata=new ArrayList();
私有ArrayList lobbydata=新ArrayList();
受保护的RemoteImp()引发RemoteException
{
}
@凌驾
公共ArrayList getOpdata()引发RemoteException{
返回opdata;
}
@凌驾
公共void SendMyData(整数分数、字符串名称)引发RemoteException{
//opdata.add(String.valueOf(score));
for(TempPlayer播放器:opdata){
如果(player.player==名称){
player.setScore(分数);
}否则{
添加(新的TempPlayer(分数、名称));
}
}  
}
}

现在,当我试图通过调用
Remote.SendData
来调用
SendData
时,它会转到Integer.java页面。我现在的问题是什么会导致这种情况,以及如何让程序真正转到我希望它转到的函数?

您尝试过没有调试器吗?另外,在第一个代码段中,您没有打印异常,因此如何确保没有引发异常?当您使用rmi时,这意味着您有使用rmi代理对象的java进程。在您的实现中,SendMyData方法不返回任何内容当我向SendData方法添加一个返回值(布尔值)时,它现在将程序抛出到eventdispatchthread中。正如我之前在使用调试器时所做的那样(昨天),我确信debbugger不是问题所在。“将程序抛出事件调度线程”是毫无意义的,正如您描述的所有其他症状一样。您会遇到异常,需要在问题中包含相应的堆栈跟踪。
public class RMIserver {
    public static void main(String[] args ) throws RemoteException, AlreadyBoundException {
        RemoteImp imp = new RemoteImp();
        Registry reg = LocateRegistry.createRegistry(1099);
        reg.rebind("TestRMI", imp);
        System.out.println("Server is Started");        
    }
}
public interface TestRemote extends Remote {

    public ArrayList<TempPlayer> getOpdata() throws RemoteException;
    public void SendMyData(int score, String player) throws RemoteException;}
        private static final long serialVersionUID = 1L;
    private ArrayList<TempPlayer> opdata = new ArrayList<TempPlayer>();
    private ArrayList<String> lobbydata = new ArrayList<String>();
    protected RemoteImp() throws RemoteException
    {

    }
    @Override
    public ArrayList<TempPlayer> getOpdata() throws RemoteException {
        return  opdata;
    }

    @Override
    public void SendMyData(int score, String name) throws RemoteException {
        //opdata.add(String.valueOf(score));

        for (TempPlayer player : opdata) {
            if (player.player == name) {
                player.setScore(score);
            } else {
                opdata.add(new TempPlayer(score, name));
            }
        }  
    }
}