Search code examples
javac++java-native-interface

Get subclass Rectangle2D.Double member via JNI


Assume following class

import java.awt.geom.Rectangle2D;

class SomeJavaClass
{
    public SomeJavaClass()
    {
        m_rect = new Rectangle2D.Double();
    }
    Rectangle2D.Double m_rect;
}

and following C++ code

jclass someJavaCls = env->FindClass("my/package/SomeJavaClass");
jfieldID rectID = env->GetFieldID(someJavaCls, "m_rect", "Ljava/awt/geom/Rectangle2D;");

The problem is that I don't know how to access the fieldID for the m_rect. With the above GetFieldID call I get

Exception in thread "Thread-2" java.lang.NoSuchFieldError: m_rect

But also if I change the signature of GetFieldID to "Ljava/awt/geom/Rectangle2D/Double;" I get the same exception. How is this done?


Solution

  • Solution seems to be "Ljava/awt/geom/Rectangle2D$Double;" since Double is a subclass of Rectangle2D.