我用一个简单的例子开始Java RMI。实际的例子工作正常(来自roseindia),但我已经扩展了一点,我得到错误。远程接口的文件如下: -
import java.rmi.*;
public interface RemoteInterface extends Remote
{
public int add(int x,int y)throws Exception; //original line
public int sub(int x, int y)throws Exception; //added later by me
}
现在生成错误的客户端文件的代码段是: -
b.addActionListener(new ActionListener() { // b is a JButton
public void actionPerformed(ActionEvent evt) {
int a = Integer.parseInt(t1.getText()); //t1 and t2 are TextField
int b = Integer.parseInt(t2.getText());
try {
int r = s.add(a,b);
rs.setText("Sum of two no.s=" + r); //rs is a Label
} catch (Exception epx) {
}
}
});
它工作正常。但是当我为另一个按钮添加以下内容时
b2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt1) {
int a1 = Integer.parseInt(t1.getText());
int b2 = Integer.parseInt(t2.getText());
try {
int r2 = s.sub(a1, b2);
rs.setText("Subtraction of two no.s =" + r2);
} catch (Exception epx) {
}
}
});
我收到以下错误
C:\Program Files\Java\jdk1.6.0_14\bin>java Client
Exception in thread "AWT-EventQueue-0" java.lang.AbstractMethodError: ServerImpl
ements_Stub.sub(II)I
at Client$2.actionPerformed(Client.java:65)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:19
95)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
a:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242
)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574
)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
只是一些问题会有所帮助。提前谢谢。
答案 0 :(得分:3)
你已经改变了一些东西而没有重新编译它的所有依赖项:在这种情况下你没有重新生成存根。重新编译所有内容并重新测试。