InstantiationException

I have created a proxy for an abstract Java class, and have created a .NET class that inherits from the proxy for that Java class. However, when I attempt to instantiate this .NET class, I get a java.lang.InstantiationException. Why?

This is a known issue. When you instantiate a Java proxy, the underlying Java object is instantiated, too. Similarly, when you instantiate a .NET class that inherits from a Java proxy, this also causes the underlying Java object to be instantiated. If the underlying Java object is abstract, an InstantiationException will be thrown.

This issue will be addressed in a future version of JNBridgePro, but in the meantime, the workaround is to create a concrete Java class that extends the abstract one, create a proxy for that concrete Java class, and have the .NET class inherit from the proxy of the concrete Java class. The concrete Java class should have a constructor corresponding to each of the constructors in the abstract Java class, with the same signatures, and which passes the call up the abstract class through the super() operator. For example, if a Java abstract class A has a constructor

public A(int i)

the Java concrete class C that extends it should have a constructor

public C(int i)
{
   super(i);
}

Similarly, the concrete class should implement any abstract methods in the base abstract class.