Solved

Java RMI UnmarshalException

Posted on 2006-11-01
4
330 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 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
json format text only 4 65
mapAB Challlenge 35 89
base64 decode encode 12 98
GUI builder for Eclipse? 8 11
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

760 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now