Re: java.lang.InstantiationException:$Proxy0

Gregg Wonderly <[email protected]> Mon, 9 Feb 2009 12:29:02 -0600
Newsgroups gmane.comp.java.sun.rmi
Message-ID <[email protected]>
It sounds like you are not familiar with the codebase mechanism of Java a=
nd RMI=20
which allows you to tell the remote end "where" to get classes it can't r=
esolve=20
from its classpath.

On you JVM command line, you put "-Djava.rmi.server.codebase=3DXXXX" wher=
e the=20
XXXX part is a URL that the remote end can open to "download" a jar file =
or a=20
bunch of class files from.  Using a jar is typically better.  So you migh=
t have

	-Djava.rmi.server.codebase=3Dhttp://my.server.come/jars/myclasses.jar

on the command line.  Then, you jar up your class files and put them onto=
=20
my.server.com under the directory that the /jars component of the URL ref=
ers to=20
in the http servers configuration.

Now, RMI, when it sends any classes over a remote procedure call, will=20
"annotate" them with this URL, and on the remote end, when the "exported =
object"=20
is deserialized, that URL will be available to allow the behind the scene=
s=20
activities to create a URLClassLoader that will allow the client to find =
those=20
classes.

You can read http://java.sun.com/j2se/1.4.2/docs/guide/rmi/codebase.html =
for all=20
the details and perhaps that is what you need to get things going.

Gregg Wonderly

lachhman wrote:
> Actually the problem is that I have to send the stub from one object(se=
nder)
> to another object(receiver), and  this can easily be done by calling th=
e
> method of receiver which carries stub as an argument. However, the
> environment I working under does not allow any object to have a method =
to
> carry an argument of remote object. However, methods can carry argument=
s of
> basic data types( String, float etc.) and Class instance of any class t=
ype.=20
>=20
> So, what I am doing is that I am creating  a class instance of obtained=
 stub
> in sender class and sending this  as an argument to the method of recei=
ver.
> In the body of method I am re-constructing the stub from this Class
> instance(e.g., Xyz  stub =3D (Xyz) classInstance.newInstance()) , This =
throws
> an excpetion(Java.lang.InstantiationExceptio:$Proxy0).=20
>=20
> As I understand, there is no issue of codebase property as the sender i=
s
> able to get the stub from Naming.lookup(args) and call remote method on=
 this
> stub.=20
>=20
> The actual code is too big as it contains code for other things. Howeve=
r, I
> have just simulated the problem in two classes=E2=80=94Sender and Recei=
ver.=20
>=20
> Here is the code and stack trace.
>=20
> import java.net.MalformedURLException;
> import java.rmi.Naming;
> import java.rmi.NotBoundException;
> import java.rmi.RemoteException;
> import net.abc.lsn.LightInterface;
>=20
> public class Sender {
> 		=20
> 	public static void main(String[] args)
> 	{
> 		try {
> 		=09
> 			Receiver receiver =3D new Receiver();
> 			LightInterface li =3D (LightInterface)Naming.lookup("room1");
> 			System.out.println("Lookup done: got stub.");
> 			System.out.println("Creating Class instance");
> 			Class classInstance =3D li.getClass();
> 			System.out.println("Class instance of stub created.");
> 		=09
> 			receiver.setRemote(classInstance);
> 				=09
> 		} catch (RemoteException e) {
> 			// TODO Auto-generated catch block
> 			e.printStackTrace();
> 		} catch (NotBoundException e) {
> 			// TODO Auto-generated catch block
> 			e.printStackTrace();
> 		} catch (MalformedURLException e) {
> 			// TODO Auto-generated catch block
> 			e.printStackTrace();
> 		}
> 	}
> }=20
>=20
> import java.net.MalformedURLException;
> import java.rmi.Naming;
> import java.rmi.NotBoundException;
> import java.rmi.RemoteException;
> import net.abc.lsn.LightInterface;
>=20
> public class Receiver {
>=20
> 	public LightInterface r;
> =09
> 	public void setRemote(Class classInstance)
> =09
> 	{
> 	=09
> 		try {
> 			r=3D(LightInterface)classInstance.newInstance();
> 		} catch (InstantiationException e1) {
> 			// TODO Auto-generated catch block
> 			e1.printStackTrace();
> 		} catch (IllegalAccessException e1) {
> 			// TODO Auto-generated catch block
> 			e1.printStackTrace();
> 		}
> 	=09
> 			=09
> 		try {
> 			r.on();
> 		} catch (RemoteException e) {
> 			// TODO Auto-generated catch block
> 			e.printStackTrace();
> 		}
> 	}
>=20
> }
>=20
> Stack trace:=20
>=20
> java.lang.InstantiationException: $Proxy0
>         at java.lang.Class.newInstance0(Unknown Source)
>         at java.lang.Class.newInstance(Unknown Source)
>         at net.ponder2.managedobject.Receiver.setRemote(Unknown Source)
>         at net.ponder2.managedobject.Sender.main(Unknown Source)
> Exception in thread "main" java.lang.NullPointerException
>         at net.ponder2.managedobject.Receiver.setRemote(Unknown Source)
>         at net.ponder2.managedobject.Sender.main(Unknown Source)
>=20
>=20
>=20
> Gregg Wonderly wrote:
>> lachhman wrote:
>>> I am getting this exception(java.lang.InstantiationException:$Proxy0)
>>> while
>>> reconstructing the stub/proxy from the Class instance of stub/proxy.
>> What would be helpful is the full stack trace and more information abo=
ut
>> whether=20
>> "I am getting...while reconstructing" refers to actions you've program=
med=20
>> explicitly (such as marshalling and unmarshalling to disk etc.) or
>> something=20
>> associated with the client activities.  Knowing what is being
>> instantiated, in=20
>> particular might reveal more about the source of the problem.
>>
>> It might be a simple codebase problem where the URL(s) in your codebas=
e
>> are not=20
>> actually reachable from the client, but it's hard to tell from the
>> information=20
>> you've provided.
>>
>> Gregg Wonderly
>>
>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D
>> To unsubscribe, send email to [email protected] and include in the
>> body
>> of the message "signoff RMI-USERS".  For general help, send email to
>> [email protected] and include in the body of the message "help".
>>
>> For a list of frequently asked RMI questions please refer to:
>> http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html
>>
>> To view past RMI-USERS postings, please see:
>> http://archives.java.sun.com/archives/rmi-users.html
>>
>>
>=20

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
To unsubscribe, send email to [email protected] and include in the bo=
dy
of the message "signoff RMI-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

For a list of frequently asked RMI questions please refer to:
http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html

To view past RMI-USERS postings, please see:
http://archives.java.sun.com/archives/rmi-users.html