Solved

Java RMI UnmarshalException

Posted on 2006-11-01
4
336 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
[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
  • 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 250 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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:
The viewer will learn how to implement Singleton Design Pattern in Java.

631 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