?
Solved

RMI binding error (In the Client GUI)

Posted on 2005-03-13
10
Medium Priority
?
301 Views
Last Modified: 2013-12-29
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
Comment
Question by:_Esam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 6

Expert Comment

by:durgaprasad_j
ID: 13528852
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
 

Author Comment

by:_Esam
ID: 13530400
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
 
LVL 6

Expert Comment

by:durgaprasad_j
ID: 13532612
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!

 

Author Comment

by:_Esam
ID: 13533927
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
 
LVL 6

Accepted Solution

by:
durgaprasad_j earned 500 total points
ID: 13534911
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
 

Author Comment

by:_Esam
ID: 13570748
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
 
LVL 6

Expert Comment

by:durgaprasad_j
ID: 13572071
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
 

Author Comment

by:_Esam
ID: 13572297
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
 
LVL 6

Expert Comment

by:durgaprasad_j
ID: 13572562
ok looks good
good luck

DP
0
 
LVL 6

Expert Comment

by:durgaprasad_j
ID: 13572964
:) thanks for accepting
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question