我在Java RMI中很新,並且遇到了未綁定異常的問題。我知道這裏有很多帖子,但任何我已經試過最後幾個小時並沒有真正幫助..Rmi:未綁定異常
這裏是服務器和客戶端的代碼。任何幫助都很好,預先感謝。
最後一件事,當我正在運行母版時發現異常,當我運行服務器時沒有發現錯誤。
站長:
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.util.Scanner;
import java.rmi.registry.LocateRegistry;
public class Master {
private ITaskBag1 tb;
private String name = "rmi://" + "127.0.0.1" +":"+1099+"/TaskBagServer";
private int rescount = 0,listcount=0;
private boolean finished = false;
private ArrayList<String> tasks = new ArrayList<String>();
private Random rand;
private double rkey;
public static void main(String[] args){
//pithano lathos
try {
Master m = new Master(args);
} catch (Exception exc) { }
}
Master (String[] args){
rand = new Random();
String url="";
String s1="",s2="",s3="",myLine="",key="";
File myFile=null;
File imgFile = null;
String myFileName="";
String myFileName2="";
StringTokenizer st;
BufferedReader br=null;
int numoftokens = 0;
int endframe = 0;
int degrees = 0;
int eikona = 001;
int i;
double scale = 1.0;
byte[] imageInByte = null;
imageData imdat = null;
imageResult imres = null;
Boolean registered = false;
//Register to ITaskbag
try { //try 1
//try to register
tb = (ITaskBag1) Naming.lookup(name);
}
}
}
服務器:
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.LocateRegistry;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
public class TaskBagServer{
public static void main(String args[]) {
final int DEFAULT_PORT = 1099;
String sport="";
int port=DEFAULT_PORT;
String connectionstring="//127.0.0.1/TaskbagServer";
//String porterror = "Invalid port specified, " + DEFAULT_PORT + " assumed";
try {
//LocateRegistry.createRegistry(1099);
// connectionstring = "//127.0.0.1:"+port+"/TaskbagServer";
java.rmi.registry.LocateRegistry.createRegistry(1099);
} catch (RemoteException ex) {
Logger.getLogger(TaskBagServer.class.getName()).log(Level.SEVERE, null, ex);
}
try {
TaskBag1 server = new TaskBag1();
Naming.rebind("connectionstring",server);
System.out.println("Taskbag Server Bound");
}
}
}
非常感謝大家。刪除引號後,問題仍然存在.. –