下面是关于RMI的实验。。编译FirstRemote没有出错,不过编译FirstService的时候出现错误了。
这是FirstRemote.javapackage rmi;import java.rmi.Remote;
import java.rmi.*;public interface FirstRemote extends Remote {
       public void hello()throws RemoteException;
       public int getFibonacciItem(int index)throws RemoteException;
       public double arithmetic(String arg)throws RemoteException;
}
下面是FirstService.javapackage rmi;import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.*;public class FirstService extends UnicastRemoteObject implements FirstRemote { public FirstService()throws RemoteException{
super();
}

public void hello() throws RemoteException {
// TODO Auto-generated method stub
System.out.println("Hello World");
}

public int getFibonacciItem(int index){
  if(index==1||index==2){
  return 1;
  }else{
       return getFibonacciItem(index-2)+getFibonacciItem(index-1);  
  }
 
}

public double arithmetic(String str){
String[] digit = str.split("[-+*/]+");
String[] operator = str.split("[0-9.]+");
int len = operator.length;
Stack stack1 = new Stack<String>();
Stack stack2 = new Stack<String>();
double left,right,result;
stack1.push(digit[0]);
for(int i=1;i<len;i++){
stack1.push(digit[i]);
if(operator[i].equals("*")||operator[i].equals("/")){
right = Double.valueOf((String)stack1.pop());
    left = Double.valueOf((String)stack1.pop());
    result = jisuan(operator[i],left,right);
    stack1.push(new Double(result).toString());
}else{
stack2.push(operator[i]);
}
}
while(!stack2.isEmpty()){
    right = Double.valueOf((String)stack1.pop());
        left = Double.valueOf((String)stack1.pop());
    result = jisuan((String)stack2.pop(),left,right);
    stack1.push(new Double(result).toString());
}
return Double.valueOf((String)stack1.pop());
}

public double jisuan(String operator,double lf,double r){
            if(operator.equals("+"))
             return lf+r;
            if(operator.equals("-"))
             return lf-r;
            if(operator.equals("*"))
             return lf*r;
            if(operator.equals("/"))
             return lf/r;
return 0;
}}

解决方案 »

  1.   

    Stack stack1 = new Stack<String>();
    Stack stack2 = new Stack<String>();因为你用的是 JDK 1.5 或者以后版本的编译器,在这些版本中 Stack 是个泛型类,需要加上泛型参数,否则会报类型安全警告,改成这样:Stack<String> stack1 = new Stack<String>();
    Stack<String> stack2 = new Stack<String>();
      

  2.   

    另外,以后发图的话不要使用百度或者 QQ 空间中的图片,你登录的话可以看到这些图片,我们是看不到的。点击你头像下面的账号,进入你的 CSDN 空间,在第五个标签有“相册”,你可以把图片上传到那里,再把地址放到回复框的 IMG 标签中就可以了。
      

  3.   

    未经检查错误就是该catch的Exception你没catch你在每个方法后面加上throws Exception就没问题了