java - RMI ClassCastException to remote interface -
hi having problem rmi.
i have error when run it.
java.lang.classcastexception: com.sun.proxy.$proxy0 cannot cast rmi.converter
this interface
converter.java
import java.rmi.remoteexception; public interface converter { double celciuskelvin (double a) throws remoteexception; double celciusfahrenheit (double a) throws remoteexception; double fahrenheitkelvin (double a) throws remoteexception; double fahrenheitcelcius (double a) throws remoteexception; double kelvincelcius (double a) throws remoteexception; double kelvinfahrenheit (double a) throws remoteexception; double atmospascal (double a) throws remoteexception; double atmospsi (double a) throws remoteexception; double pascalatmos (double a) throws remoteexception; double pascalpsi (double a) throws remoteexception; double psiatmos (double a) throws remoteexception; double psipascal (double a) throws remoteexception; }
this remote method
converterimp.java
import java.rmi.remoteexception; import java.rmi.server.unicastremoteobject; public class converterimp extends unicastremoteobject implements converter { public converterimp() throws remoteexception { } double convert; @override public double celciuskelvin(double a) throws remoteexception { convert = a+273.15; return convert; } @override public double celciusfahrenheit(double a) throws remoteexception { convert = (a*1.8)+32; return convert; } @override public double fahrenheitkelvin(double a) throws remoteexception { convert = (a+459.67)*5/9; return convert; } @override public double fahrenheitcelcius(double a) throws remoteexception { convert=(a-32)/(9/5); return convert; } @override public double kelvincelcius(double a) throws remoteexception { convert = - 273.15; return convert; } @override public double kelvinfahrenheit(double a) throws remoteexception { convert=(a-273.15)* 1.8 + 32.00; return convert; } @override public double atmospascal(double a) throws remoteexception { convert = a*101325; return convert; } @override public double atmospsi(double a) throws remoteexception { convert = a*14.6959488; return convert; } @override public double pascalatmos(double a) throws remoteexception { convert = a/101325; return convert; } @override public double pascalpsi(double a) throws remoteexception { convert=a*0.000145037; return convert; } @override public double psiatmos(double a) throws remoteexception { convert = a*0.0680459639; return convert; } @override public double psipascal(double a) throws remoteexception { convert =a*6894.75729; return convert; } }
this gui client.
package projectrmiclient; import java.rmi.registry.locateregistry; import java.rmi.registry.registry; import rmi.converter; public class projectrmiclient extends javax.swing.jframe { public projectrmiclient() { initcomponents(); } string num = ""; string str = ""; @suppresswarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="generated code"> private void initcomponents() { jscrollpane1 = new javax.swing.jscrollpane(); jtextpane1 = new javax.swing.jtextpane(); jbutton1 = new javax.swing.jbutton(); jbutton2 = new javax.swing.jbutton(); jbutton3 = new javax.swing.jbutton(); jbutton4 = new javax.swing.jbutton(); jbutton5 = new javax.swing.jbutton(); jbutton6 = new javax.swing.jbutton(); jbutton7 = new javax.swing.jbutton(); jbutton8 = new javax.swing.jbutton(); jbutton9 = new javax.swing.jbutton(); jbutton10 = new javax.swing.jbutton(); jbutton11 = new javax.swing.jbutton(); jlabel1 = new javax.swing.jlabel(); jbutton12 = new javax.swing.jbutton(); jbutton13 = new javax.swing.jbutton(); jbutton14 = new javax.swing.jbutton(); jbutton15 = new javax.swing.jbutton(); jbutton16 = new javax.swing.jbutton(); jbutton17 = new javax.swing.jbutton(); jbutton18 = new javax.swing.jbutton(); jbutton19 = new javax.swing.jbutton(); jbutton20 = new javax.swing.jbutton(); jbutton21 = new javax.swing.jbutton(); jbutton22 = new javax.swing.jbutton(); jbutton23 = new javax.swing.jbutton(); jlabel2 = new javax.swing.jlabel(); jlabel3 = new javax.swing.jlabel(); jlabel4 = new javax.swing.jlabel(); setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close); jtextpane1.seteditable(false); jscrollpane1.setviewportview(jtextpane1); jbutton1.settext("1"); jbutton1.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton1actionperformed(evt); } }); jbutton2.settext("2"); jbutton2.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton2actionperformed(evt); } }); jbutton3.settext("3"); jbutton3.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton3actionperformed(evt); } }); jbutton4.settext("4"); jbutton4.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton4actionperformed(evt); } }); jbutton5.settext("5"); jbutton5.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton5actionperformed(evt); } }); jbutton6.settext("6"); jbutton6.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton6actionperformed(evt); } }); jbutton7.settext("7"); jbutton7.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton7actionperformed(evt); } }); jbutton8.settext("8"); jbutton8.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton8actionperformed(evt); } }); jbutton9.settext("9"); jbutton9.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton9actionperformed(evt); } }); jbutton10.settext("0"); jbutton10.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton10actionperformed(evt); } }); jbutton11.settext("cancel"); jbutton11.settooltiptext(""); jbutton11.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton11actionperformed(evt); } }); jlabel1.settext("temperature"); jbutton12.settext("c~f"); jbutton12.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton12actionperformed(evt); } }); jbutton13.settext("f~c"); jbutton14.settext("k~c"); jbutton15.settext("c~k"); jbutton16.settext("f~k"); jbutton17.settext("k~f"); jbutton18.settext("a~psi"); jbutton19.settext("psi~a"); jbutton20.settext("pas~a"); jbutton21.settext("a~pas"); jbutton22.settext("psi-pas"); jbutton22.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton22actionperformed(evt); } }); jbutton23.settext("pas~a"); jlabel2.settext("pressure"); jlabel3.settext("result"); javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane()); getcontentpane().setlayout(layout); layout.sethorizontalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addcontainergap() .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.trailing, false) .addcomponent(jlabel4, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jlabel3, javax.swing.grouplayout.alignment.leading) .addcomponent(jscrollpane1, javax.swing.grouplayout.default_size, 205, short.max_value) .addgroup(layout.createsequentialgroup() .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.trailing) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addcomponent(jbutton1, javax.swing.grouplayout.preferred_size, 45, javax.swing.grouplayout.preferred_size) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addcomponent(jbutton2, javax.swing.grouplayout.preferred_size, 45, javax.swing.grouplayout.preferred_size) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addcomponent(jbutton3, javax.swing.grouplayout.preferred_size, 45, javax.swing.grouplayout.preferred_size)) .addgroup(layout.createsequentialgroup() .addcomponent(jbutton4, javax.swing.grouplayout.preferred_size, 45, javax.swing.grouplayout.preferred_size) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addcomponent(jbutton5, javax.swing.grouplayout.preferred_size, 45, javax.swing.grouplayout.preferred_size) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addcomponent(jbutton6, javax.swing.grouplayout.preferred_size, 45, javax.swing.grouplayout.preferred_size))) .addgroup(layout.createsequentialgroup() .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.trailing) .addcomponent(jbutton7, javax.swing.grouplayout.preferred_size, 45, javax.swing.grouplayout.preferred_size) .addcomponent(jbutton10, javax.swing.grouplayout.preferred_size, 45, javax.swing.grouplayout.preferred_size)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addcomponent(jbutton11) .addgroup(layout.createsequentialgroup() .addcomponent(jbutton8, javax.swing.grouplayout.preferred_size, 45, javax.swing.grouplayout.preferred_size) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addcomponent(jbutton9, javax.swing.grouplayout.preferred_size, 45, javax.swing.grouplayout.preferred_size))))) .addgap(36, 36, 36))) .addpreferredgap(javax.swing.layoutstyle.componentplacement.unrelated) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading, false) .addcomponent(jbutton18, javax.swing.grouplayout.preferred_size, 92, javax.swing.grouplayout.preferred_size) .addcomponent(jbutton19, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jbutton20, javax.swing.grouplayout.preferred_size, 92, javax.swing.grouplayout.preferred_size)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.unrelated) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.trailing, false) .addcomponent(jbutton22, javax.swing.grouplayout.alignment.leading, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jbutton21, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jbutton23, javax.swing.grouplayout.preferred_size, 92, javax.swing.grouplayout.preferred_size))) .addgroup(layout.createsequentialgroup() .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.trailing, false) .addcomponent(jlabel1, javax.swing.grouplayout.alignment.leading, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jbutton12, javax.swing.grouplayout.preferred_size, 92, javax.swing.grouplayout.preferred_size) .addcomponent(jbutton14, javax.swing.grouplayout.alignment.leading, javax.swing.grouplayout.preferred_size, 92, javax.swing.grouplayout.preferred_size)) .addcomponent(jbutton13, javax.swing.grouplayout.preferred_size, 92, javax.swing.grouplayout.preferred_size)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.trailing, false) .addcomponent(jbutton16, javax.swing.grouplayout.alignment.leading, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jbutton15, javax.swing.grouplayout.alignment.leading, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jbutton17, javax.swing.grouplayout.preferred_size, 92, javax.swing.grouplayout.preferred_size))) .addcomponent(jlabel2)) .addcontainergap(20, short.max_value)) ); layout.setverticalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgap(34, 34, 34) .addcomponent(jscrollpane1, javax.swing.grouplayout.preferred_size, 46, javax.swing.grouplayout.preferred_size) .addgap(18, 18, 18) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jbutton3) .addcomponent(jbutton2) .addcomponent(jbutton1)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jbutton4) .addcomponent(jbutton5) .addcomponent(jbutton6)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jbutton7) .addcomponent(jbutton8) .addcomponent(jbutton9)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jbutton11) .addcomponent(jbutton10)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.unrelated) .addcomponent(jlabel3)) .addgroup(layout.createsequentialgroup() .addcontainergap() .addcomponent(jlabel1) .addgap(7, 7, 7) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jbutton15) .addcomponent(jbutton12)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jbutton16) .addcomponent(jbutton13)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jbutton17) .addcomponent(jbutton14)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addcomponent(jlabel2) .addgap(18, 18, 18) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jbutton18) .addcomponent(jbutton21)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addcomponent(jbutton22) .addcomponent(jbutton19)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jbutton20) .addcomponent(jbutton23)))) .addpreferredgap(javax.swing.layoutstyle.componentplacement.unrelated) .addcomponent(jlabel4, javax.swing.grouplayout.preferred_size, 52, javax.swing.grouplayout.preferred_size) .addcontainergap(20, short.max_value)) ); pack(); }// </editor-fold> private void jbutton1actionperformed(java.awt.event.actionevent evt) { str = evt.getactioncommand(); num = num + str; jtextpane1.settext(num); } private void jbutton2actionperformed(java.awt.event.actionevent evt) { str = evt.getactioncommand(); num = num + str; jtextpane1.settext(num); } private void jbutton3actionperformed(java.awt.event.actionevent evt) { str = evt.getactioncommand(); num = num + str; jtextpane1.settext(num);// todo add handling code here: } private void jbutton4actionperformed(java.awt.event.actionevent evt) { str = evt.getactioncommand(); num = num + str; jtextpane1.settext(num);// todo add handling code here: } private void jbutton5actionperformed(java.awt.event.actionevent evt) { str = evt.getactioncommand(); num = num + str; jtextpane1.settext(num);// todo add handling code here: } private void jbutton6actionperformed(java.awt.event.actionevent evt) { str = evt.getactioncommand(); num = num + str; jtextpane1.settext(num);// todo add handling code here: } private void jbutton7actionperformed(java.awt.event.actionevent evt) { str = evt.getactioncommand(); num = num + str; jtextpane1.settext(num);// todo add handling code here: } private void jbutton8actionperformed(java.awt.event.actionevent evt) { str = evt.getactioncommand(); num = num + str; jtextpane1.settext(num);// todo add handling code here: } private void jbutton9actionperformed(java.awt.event.actionevent evt) { str = evt.getactioncommand(); num = num + str; jtextpane1.settext(num);// todo add handling code here: } private void jbutton10actionperformed(java.awt.event.actionevent evt) { str = evt.getactioncommand(); num = num + str; jtextpane1.settext(num);// todo add handling code here: } private void jbutton11actionperformed(java.awt.event.actionevent evt) { jtextpane1.settext(""); } private void jbutton22actionperformed(java.awt.event.actionevent evt) { // todo add handling code here: } private void jbutton12actionperformed(java.awt.event.actionevent evt) { try { // fire localhost port 1099 registry myregistry = locateregistry.getregistry("127.0.0.1", 1099); // search mymessage service converter impl = (converter) myregistry.lookup("ptconverter"); if(!jtextpane1.gettext().isempty()) { double input = double.parsedouble(jtextpane1.gettext()); // call server's method double result=impl.celciusfahrenheit(input); string answer = result + "fahrenheit"; jlabel4.settext(answer); } } catch (exception e) { e.printstacktrace(); } } /** * @param args command line arguments */ public static void main(string args[]) { /* set nimbus , feel */ //<editor-fold defaultstate="collapsed" desc=" , feel setting code (optional) "> /* if nimbus (introduced in java se 6) not available, stay default , feel. * details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { (javax.swing.uimanager.lookandfeelinfo info : javax.swing.uimanager.getinstalledlookandfeels()) { if ("nimbus".equals(info.getname())) { javax.swing.uimanager.setlookandfeel(info.getclassname()); break; } } } catch (classnotfoundexception ex) { java.util.logging.logger.getlogger(projectrmiclient.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (instantiationexception ex) { java.util.logging.logger.getlogger(projectrmiclient.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (illegalaccessexception ex) { java.util.logging.logger.getlogger(projectrmiclient.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (javax.swing.unsupportedlookandfeelexception ex) { java.util.logging.logger.getlogger(projectrmiclient.class.getname()).log(java.util.logging.level.severe, null, ex); } //</editor-fold> //</editor-fold> /* create , display form */ java.awt.eventqueue.invokelater(new runnable() { public void run() { new projectrmiclient().setvisible(true); } }); } // variables declaration - not modify private javax.swing.jbutton jbutton1; private javax.swing.jbutton jbutton10; private javax.swing.jbutton jbutton11; private javax.swing.jbutton jbutton12; private javax.swing.jbutton jbutton13; private javax.swing.jbutton jbutton14; private javax.swing.jbutton jbutton15; private javax.swing.jbutton jbutton16; private javax.swing.jbutton jbutton17; private javax.swing.jbutton jbutton18; private javax.swing.jbutton jbutton19; private javax.swing.jbutton jbutton2; private javax.swing.jbutton jbutton20; private javax.swing.jbutton jbutton21; private javax.swing.jbutton jbutton22; private javax.swing.jbutton jbutton23; private javax.swing.jbutton jbutton3; private javax.swing.jbutton jbutton4; private javax.swing.jbutton jbutton5; private javax.swing.jbutton jbutton6; private javax.swing.jbutton jbutton7; private javax.swing.jbutton jbutton8; private javax.swing.jbutton jbutton9; private javax.swing.jlabel jlabel1; private javax.swing.jlabel jlabel2; private javax.swing.jlabel jlabel3; private javax.swing.jlabel jlabel4; private javax.swing.jscrollpane jscrollpane1; private javax.swing.jtextpane jtextpane1; // end of variables declaration }
i developed gui using gui builder on netbeans. problem when pressed jbutton12. show error stated.
you appear have created copy of remote interface in different package client. can't that. remote interface has same on both sides: the same, , not include changing package, or indeed else.
Comments
Post a Comment