Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

RMI binding error (In the Client GUI)

Hi,
I get error that it can't find the

>>myServerObject

That I defined in the main method:
>>myRMIInterface myServerObject = (myRMIInterface) Naming.lookup("rmi://"+serverName+"/myRMIImplInstance");

This  >>myServerObject
is called twice in the JTable >>>at

 private void makeRemainingTabs() {
              tabbedPane.addTab("View Courses", new JScrollPane(new JTable(new MyTableModel(myServerObject.getCoursesTaken(id)))));
          tabbedPane.addTab("View Requirements", new JScrollPane(new JTable(new MyTableModel(myServerObject.getRequiredCourses(id)))));


>>(myServerObject.getRequiredCourses(id)) returns a vector ---
It seems that I didn't declare such a Vector.....
Can't figure out how I do that ........
Need help

THe complete client side GUI class is as follows:



import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.lang.*;
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;


public class CoursePlanner extends JFrame  {
     private JTabbedPane tabbedPane;
   
       private int id = 1204;




  private void setGui() {
    try {
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               tabbedPane = new JTabbedPane();
      JPanel p = new JPanel();
               p.add(new JLabel("Some initial message to show"));
               tabbedPane.addTab("UST Course Planner", p);
      getContentPane().add(tabbedPane);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

     private boolean logon() {
          return "secret".equals(JOptionPane.showInputDialog("Enter password"));
     }

     private void makeRemainingTabs() {
              tabbedPane.addTab("View Courses", new JScrollPane(new JTable(new MyTableModel(myServerObject.getCoursesTaken(id)))));
          tabbedPane.addTab("View Requirements", new JScrollPane(new JTable(new MyTableModel(myServerObject.getRequiredCourses(id)))));
     }






public static void main(String[] argv)
                {
                System.setSecurityManager(new RMISecurityManager());
                if (argv.length != 1)
                        {
                        System.out.println("usage: java myRMIClient <IP address of host running RMI server>");
                        System.exit(0);
                        }
                String serverName = argv[0];
                try
                        {
                        //bind server object to object in client
                        myRMIInterface myServerObject = (myRMIInterface) Naming.lookup("rmi://"+serverName+"/myRMIImplInstance");
                                    }
                catch(Exception e)
                        {
                        System.out.println("Exception occured: " + e);
                        System.exit(0);
                        }
                System.out.println("RMI connection successful");

    CoursePlanner f = new CoursePlanner();
    f.setGui();
    f.setSize(500, 300);
    f.setVisible(true);
          if (f.logon()) {
               f.makeRemainingTabs();
          }
  }

}








PLs let me know

Thanks.
_Esam
                                    
0
_Esam
Asked:
_Esam
  • 6
  • 4
1 Solution
 
durgaprasad_jCommented:
hi,
first of all, is that rmi address is bound in the rmi server.
try specifying the port also. like below
 myRMIInterface myServerObject = (myRMIInterface) Naming.lookup("rmi://"+serverName+":1099/myRMIImplInstance");

Here , you are looking up already existing rmi address which is bound in the rmi server.

Can you post the execption stacktrace. To do the stackTrace you have to do this

catch(Exception e)
{
              System.out.println("Exception occured: " + e);
              e.printStackTrace(); //Can you post the output of this part
              System.exit(0);
}

DP
0
 
_EsamAuthor Commented:
Hi,
DO you think the problem could be how I declared / accessed the
>>myServerObject
in the main method but already accessed it in another method (twice ) ....this is giving the two errors....could you look carefully pls if that could be the error....

>>My problem was how do I access it  >>> then use it in the methods that I used...


THis  method>>

private void makeRemainingTabs() {
            tabbedPane.addTab("View Courses", new JScrollPane(new JTable(new MyTableModel(myServerObject.getCoursesTaken(id)))));
          tabbedPane.addTab("View Requirements", new JScrollPane(new JTable(new MyTableModel(myServerObject.getRequiredCourses(id)))));

myServerObject was only defined in the main method?


Please advise..
Thanks.
_Esam
0
 
durgaprasad_jCommented:
hi,

the way you are accessing is fine. Can you post the errors with stacktrace ? It is easy to analize if there is stack trace.

if that code is not big, can you post the whole code here ??.

declare myServerObject globally so that you can access it throgh out your whole program.

are you getting compile time errors OR runtime errors ?? [please post the code or errors stacktrace].

Hope this helps
DP
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
_EsamAuthor Commented:
Yes, I needed a global variable > a reference to the remote object.
And I had to inilialize it in the CoursePlanner constructor.......
Although it's working, I am not happy with how I set up the logon() method.
I would like to have a remote method executed on this logon() method.

>> the method would be:
      myServerObject.verify(id, password)

And this id, and password should be extracted from  two fields inside logon();
I need to add a action listener for a "OK" button to execute this remote method...

Please provide some guidance ........

THanks..
_Esam
0
 
durgaprasad_jCommented:
hi,
    first of all, what errors are you getting when you are calling rmi methods??
 
    for calling verify method, whenever the submit button clicked.. you have to add a action listener to that button
 
    suppose if the jbutton is jb.
   
    jb.addActionListener(new ActionListener()
     {
                public void actionPerformed(ActionEvent e)
                {
                          //call your verify method here.
                }
     });

DP
0
 
_EsamAuthor Commented:
Hi durgaprasad_j,
Indeed I tried your way.
My problem is I am not getting any result.
I can't can't the value from a textfield.

Please let me know what could be the problem.
Here is my code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.lang.*;
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;


public class CoursePlanner3 extends JFrame{

     private static myRMIInterface myServerObject = null;
     private int id = 0;
     private JButton okButton;
     private JTextField idField;
     private JPasswordField passwordField;
     private JTable table;


     public CoursePlanner3(myRMIInterface server){
           myServerObject = server;
           idField = new JTextField(10);
           okButton = new JButton("OK");
           okButton.addActionListener (new ActionListener(){
                               public void actionPerformed(ActionEvent event)
                               {
                                    try{
                                    id = Integer.parseInt(idField.getText());
                                    getTable();

                                    }

                                    catch(Exception e){
                                        e.printStackTrace();}
                               }
                         });

                         JPanel topPanel = new JPanel();
                         topPanel.setLayout (new BorderLayout());
                         topPanel.add(idField, BorderLayout.NORTH);
                         topPanel.add(okButton, BorderLayout.CENTER);
                         Container c = getContentPane();
                         c.setLayout(new BorderLayout());
                         c.add(topPanel, BorderLayout.NORTH);
                         //c.add(table, BorderLayout.CENTER);

                         getTable();
                         setSize(500,500);
                         setVisible(true);
                    }


           private void getTable(){

          try{
                final int id = Integer.parseInt(idField.getText());
                table = new JTable(new MyTableModel(myServerObject.getCoursesTaken(id)));
               Container c = getContentPane();
               //c.remove(2);
               c.add(table, BorderLayout.CENTER);
               c.validate();
          }

          catch(Exception sqlex){}

           }


public static void main(String[] argv)
                {
               System.setSecurityManager(new RMISecurityManager());
                if (argv.length != 1)
                        {
                        System.out.println("usage: java myRMIClient <IP address of host running RMI server>");
                        System.exit(0);
                        }
                String serverName = argv[0];
                try
                        {
                        //bind server object to object in client
                        myServerObject = (myRMIInterface) Naming.lookup("rmi://"+serverName+"/myRMIImplInstance");
                                                            }
                catch(Exception e)
                        {
                        System.out.println("Exception occured: " + e);
                        System.exit(0);
                        }
                System.out.println("RMI connection successful");

    CoursePlanner3 f = new CoursePlanner3(myServerObject);

  }

}



Problem is I can't get the value of id from the textbox...
It doesn't give me the value.

Could you please see if the is any kind of logical swing error ???

THanks.
_Esam
0
 
durgaprasad_jCommented:
hi,

you code looks fine.

 try{
                final int id = Integer.parseInt(idField.getText());
                table = new JTable(new MyTableModel(myServerObject.getCoursesTaken(id)));
               Container c = getContentPane();
               //c.remove(2);
               c.add(table, BorderLayout.CENTER);
               c.validate();
 }
catch(Exception sqlex){}

In the above code snippet, you have used your own MyTableModel to create your table model. I dont know anything about that class. in the above catch statement, try to print the exception stacktrace, it will help you , whats going on , if it is the error.

catch block should be

catch(Exception sqlex)
{
       sqlex.printStackStrace();
}

if you are getting any exception errors, paste them here, it will be easy to diagnise the error.

try just printing the value of  myServerObject.getCoursesTaken(id).
try System.out.println(myServerObject.getCoursesTaken(id)); and see if it is giving correct values as you expected.

Hope this helps
Durga Prasad
0
 
_EsamAuthor Commented:
Hi durgaprasad,
I looked at your comment from the other question....

Problem is ::: I ended up making some changes to my code...
Here is what I have now.
Sorry for more code, but looks better to me .. :)
Now I want to be able to use the "id" in the other method "makeRemainigTabs"
If you have any suggestion now, please let me know..


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.lang.*;
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;


public class CoursePlannerV1 extends JFrame{
     private JTabbedPane tabbedPane;
    private static myRMIInterface myServerObject = null;
    private boolean isVerified;
    private int id = 0;
    private String password = null;
    private JTextField idField;
    private JPasswordField passwordField;
    private boolean userVerified;

    public CoursePlannerV1(myRMIInterface server){
          this.myServerObject = server;}


       private void logOn() {
    try {
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         tabbedPane = new JTabbedPane();

           JPanel logonPanel = new JPanel();

           logonPanel.setLayout( null );

          JLabel label1 = new JLabel( "UST ID:" );
          label1.setBounds( 10, 15, 150, 20 );
          logonPanel.add( label1 );

          //TextField
          idField = new JTextField();
          idField.setBounds( 10, 35, 150, 20 );
          logonPanel.add( idField );

          JLabel label2 = new JLabel( "Password:" );
          label2.setBounds( 10, 60, 150, 20 );
          logonPanel.add( label2 );

          //JPasswordField
          passwordField = new JPasswordField();
          passwordField.setBounds( 10, 80, 150, 20 );
          logonPanel.add( passwordField );

          JButton submitButton = new JButton("Log On");
          submitButton.setBounds(80, 120, 80, 20);
          logonPanel.add(submitButton);

          submitButton.addActionListener (new ActionListener(){
                    public void actionPerformed(ActionEvent event)
                                {
                                     try{
                                     final int id = Integer.parseInt(idField.getText());
                                     final String password = new String (passwordField.getPassword());
                                     System.out.println("ID = " + id);
                                   final boolean userVerified = (myServerObject.verify(id, password));
                                   System.out.println("Verification is " + userVerified);

                                     //this remote method will be invoked against the entered id and password
                                     //verified = (myServerObject.verify(stid, stpwd));
                                     //if true then make other tabs.
                                     //to make the other tabs, pass the id from textField to the method

                                     //makeRemainingTabs();
                              }

                                     catch(Exception e){
                                   e.printStackTrace();

                              }
                         }
                         }
                         );


          tabbedPane.addTab("Log On", logonPanel);
          getContentPane().add(tabbedPane);




      }

      catch (Exception e) {
           e.printStackTrace();
      }
       }//end of logOn



   /*
   //this method is not implemented yet
   private void makeRemainingTabs(){

          try{
               tabbedPane.addTab("View Courses", new JScrollPane(new JTable(new MyTableModel(myServerObject.getCoursesTaken(id)))));
         }
         catch (Exception e){
               e.printStackTrace();
         }


         try{
               tabbedPane.addTab("View Requirements", new JScrollPane(new JTable(new MyTableModel(myServerObject.getRequiredCourses(id)))));
           }
           catch (Exception e){
               e.printStackTrace();
          }

     }
*/




     public static void main(String[] argv){
          System.setSecurityManager(new RMISecurityManager());
               if (argv.length != 1)
                  {
                      System.out.println("usage: java myRMIClient <IP address of host running RMI server>");
                     System.exit(0);
                 }
             String serverName = argv[0];
                 try
                      {
                          //bind server object to object in client
                         myServerObject = (myRMIInterface) Naming.lookup("rmi://"+serverName+"/myRMIImplInstance");
                          }
                 catch(Exception e)
                     {
                         System.out.println("Exception occured: " + e);
                         System.exit(0);
                     }

         System.out.println("RMI connection successful");

         CoursePlannerV1 cpv1 = new CoursePlannerV1(myServerObject);

         cpv1.logOn();
         cpv1.setSize(500, 300);
         cpv1.setVisible(true);
    }
}


Thanks.
_Esam

0
 
durgaprasad_jCommented:
ok looks good
good luck

DP
0
 
durgaprasad_jCommented:
:) thanks for accepting
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now