Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Java RMI UnmarshalException

Posted on 2006-11-01
4
Medium Priority
?
351 Views
Last Modified: 2010-03-31
Hi experts,


I try to run the simple example of RMI but I encountered an error.  I have generated all the required stubs but still it gives me the following error


An error occured
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
        java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
        java.lang.ClassNotFoundException: credit.CreditManagerImpl_Stub



>>>>> Directory snapshot :
11/01/2006  09:48 AM             1,142 CardBank.class
10/31/2006  05:46 PM               458 CreditCard.class
10/31/2006  05:46 PM             1,355 CreditCardImpl.class
10/31/2006  05:53 PM             2,684 CreditCardImpl_Stub.class
10/31/2006  05:46 PM               327 CreditLineExceededException.class
10/31/2006  05:48 PM               339 CreditManager.class
10/31/2006  05:48 PM             1,286 CreditManagerImpl.class
10/31/2006  05:53 PM             2,191 CreditManagerImpl_Stub.class
10/31/2006  05:46 PM               321 DuplicateAccountException.class
10/31/2006  05:46 PM               309 InvalidMoneyException.class
10/31/2006  05:46 PM               321 InvalidSignatureException.class

>>>>> Here are my relevant classes:

--------------------------------------------------------

/*
 * CardBank.java
 *
 * Created on November 1, 2006, 9:37 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package credit;

import java.util.*;
import java.rmi.*;
import java.rmi.RMISecurityManager;
import credit.*;

/**
 *
 * @author tut
 */
public class CardBank {
   
    public static void main (String args[]) {
        System.setSecurityManager(new RMISecurityManager());
       
        try {
            System.out.println("CreditManagerImpl: create a CreditManager");
            CreditManagerImpl cmi = new CreditManagerImpl();
           
           
            System.out.println("CreditManagerImpl: bind it to a name");
            Naming.rebind("cardManager", cmi);
            System.out.println("CreditManager is now ready");
        }
        catch (Exception e) {
            System.out.println("An error occured");
            e.printStackTrace();
        }
    }
   
    /** Creates a new instance of CardBank */
    public CardBank() {
    }
   
}


--------------------------------------------------


/*
 * CreditCardImpl.java
 *
 * Created on October 31, 2006, 5:23 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package credit;

import java.rmi.*;
import java.rmi.server.*;
import java.io.Serializable;

/**
 *
 * @author tut
 */
public class CreditCardImpl extends UnicastRemoteObject implements CreditCard {
    private float currentBalance = 0;
    private float creditLine = 5000f;
    private int signature = 0;
    private String accountName;

    public CreditCardImpl(String customer) throws java.rmi.RemoteException, DuplicateAccountException {
        accountName = customer;
    }
 
    public float getCreditLine() throws java.rmi.RemoteException { return creditLine; }
   
    public void payTowardsBalance(float money) throws java.rmi.RemoteException, InvalidMoneyException {
        if (money <= 0) {
            throw new InvalidMoneyException ();
        } else {
            currentBalance -= money;
        }
    }
   
    public void makePurchase(float amount, int signature) throws java.rmi.RemoteException, InvalidSignatureException, CreditLineExceededException {
        if (signature != this.signature) {
              throw new InvalidSignatureException();
        }
        if (currentBalance+amount > creditLine) {
            throw new CreditLineExceededException();
        }
        else {
            currentBalance += amount;
            creditLine -= amount;
        }
    }
   
    public void setSignature(int pin) throws java.rmi.RemoteException {
        signature = pin;
    }
}


--------------------------------------------------



package credit;
import java.rmi.*;
/*
 * CreditCard.java
 *
 * Created on October 31, 2006, 5:05 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *
 * @author tut
 */
public interface CreditCard extends java.rmi.Remote {
   

    public float getCreditLine() throws java.rmi.RemoteException;
   
    public void payTowardsBalance(float money) throws java.rmi.RemoteException, InvalidMoneyException;
   
    public void makePurchase(float amount, int signature) throws java.rmi.RemoteException, InvalidSignatureException, CreditLineExceededException;
   
    public void setSignature(int pin) throws java.rmi.RemoteException;
}




-------------------------------------------------------------------------------------------------
0
Comment
Question by:tutran91304
  • 2
4 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 17856561
What is the codebase property? Can you make sure the registry can locate the remote stubs and other classes needed? Also check that the URL that poitns to the required classes end with a trailing slash.
0
 

Author Comment

by:tutran91304
ID: 17859966
Hi girionis,

How can you set the codebase property?  The book just tells me to do a 'start rmiregistry'.  I guest my question is how can you tell the registry to to load classes from  a specific directory?
0
 
LVL 35

Accepted Solution

by:
girionis earned 750 total points
ID: 17879506
The codebase is the place from where you can load the classes needed to run your server. For more information have a look here: http://java.sun.com/j2se/1.4.2/docs/guide/rmi/codebase.html

How do you start your server?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

916 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