Solved

Java RMI UnmarshalException

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb wildfly example 2 113
Java class and jar 3 61
ArrayList Adding/settign data 3 38
Html split(text) 2 50
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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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.
Suggested Courses

752 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