Solved

Java RMI UnmarshalException

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
solarwind tftp server 2 44
Requested array size exceeds VM limit 3 84
github account with ecipse 1 42
Java SE 8u111  Lot of stuff broke 11 54
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
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.

910 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

21 Experts available now in Live!

Get 1:1 Help Now