Re: java.lang.InstantiationException:$Proxy0
lachhman <[email protected]> Mon, 9 Feb 2009 06:39:47 -0800
| Newsgroups | gmane.comp.java.sun.rmi |
|---|---|
| Message-ID | <[email protected]> |
Actually the problem is that I have to send the stub from one object(sender=
)
to another object(receiver), and this can easily be done by calling the
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 arguments of
basic data types( String, float etc.) and Class instance of any class type.=
=20
So, what I am doing is that I am creating a class instance of obtained stu=
b
in sender class and sending this as an argument to the method of receiver.
In the body of method I am re-constructing the stub from this Class
instance(e.g., Xyz stub =3D (Xyz) classInstance.newInstance()) , This thro=
ws
an excpetion(Java.lang.InstantiationExceptio:$Proxy0).=20
As I understand, there is no issue of codebase property as the sender is
able to get the stub from Naming.lookup(args) and call remote method on thi=
s
stub.=20
The actual code is too big as it contains code for other things. However, I
have just simulated the problem in two classes=E2=80=94Sender and Receiver.=
=20
Here is the code and stack trace.
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import net.abc.lsn.LightInterface;
public class Sender {
=09=09=20
=09public static void main(String[] args)
=09{
=09=09try {
=09=09=09
=09=09=09Receiver receiver =3D new Receiver();
=09=09=09LightInterface li =3D (LightInterface)Naming.lookup("room1");
=09=09=09System.out.println("Lookup done: got stub.");
=09=09=09System.out.println("Creating Class instance");
=09=09=09Class classInstance =3D li.getClass();
=09=09=09System.out.println("Class instance of stub created.");
=09=09=09
=09=09=09receiver.setRemote(classInstance);
=09=09=09=09=09
=09=09} catch (RemoteException e) {
=09=09=09// TODO Auto-generated catch block
=09=09=09e.printStackTrace();
=09=09} catch (NotBoundException e) {
=09=09=09// TODO Auto-generated catch block
=09=09=09e.printStackTrace();
=09=09} catch (MalformedURLException e) {
=09=09=09// TODO Auto-generated catch block
=09=09=09e.printStackTrace();
=09=09}
=09}
}=20
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import net.abc.lsn.LightInterface;
public class Receiver {
=09public LightInterface r;
=09
=09public void setRemote(Class classInstance)
=09
=09{
=09=09
=09=09try {
=09=09=09r=3D(LightInterface)classInstance.newInstance();
=09=09} catch (InstantiationException e1) {
=09=09=09// TODO Auto-generated catch block
=09=09=09e1.printStackTrace();
=09=09} catch (IllegalAccessException e1) {
=09=09=09// TODO Auto-generated catch block
=09=09=09e1.printStackTrace();
=09=09}
=09=09
=09=09=09=09
=09=09try {
=09=09=09r.on();
=09=09} catch (RemoteException e) {
=09=09=09// TODO Auto-generated catch block
=09=09=09e.printStackTrace();
=09=09}
=09}
}
Stack trace:=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)
Gregg Wonderly wrote:
>=20
> lachhman wrote:
>> I am getting this exception(java.lang.InstantiationException:$Proxy0)
>> while
>> reconstructing the stub/proxy from the Class instance of stub/proxy.
>=20
> What would be helpful is the full stack trace and more information about
> whether=20
> "I am getting...while reconstructing" refers to actions you've programmed=
=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.
>=20
> It might be a simple codebase problem where the URL(s) in your codebase
> are not=20
> actually reachable from the client, but it's hard to tell from the
> information=20
> you've provided.
>=20
> Gregg Wonderly
>=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
> body
> of the message "signoff RMI-USERS". For general help, send email to
> [email protected] and include in the body of the message "help".
>=20
> For a list of frequently asked RMI questions please refer to:
> http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html
>=20
> To view past RMI-USERS postings, please see:
> http://archives.java.sun.com/archives/rmi-users.html
>=20
>=20
--=20
View this message in context: http://www.nabble.com/java.lang.Instantiation=
Exception%3A%24Proxy0-tp21899006p21914069.html
Sent from the Java - RMI mailing list archive at Nabble.com.
=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