2

i have following java class:

 public class SHPObject {
    public int nSHPType;
    int nShapeId;
    public int nParts;
    int[] panPartStart;
    int panPartType;
    int nVertices;
    double[] padfX;
    double[] padfY;

    public SHPObject(int nSHPType, int nParts, int[] panPartStart, double[] padfX, double[] padfY ){
        this.nSHPType = nSHPType;
        this.nParts = nParts;
        this.panPartStart = panPartStart;
        this.padfX = padfX;
        this.padfY = padfY;
    }

 }

And i am trying to create object of this class in c++. This is my code for this:

    jclass shpObjectClass = env->FindClass("com/example/kaczor/tmc_shpreader/Shape/Shapes/SHPObject");
    jmethodID shpObjectConstructor = env->GetMethodID(shpObjectClass, "<init>", "(II[I[D[D)V");
    jobject recognition_result;
    SHPObject* a = new SHPObject[nEntities];
    for(i = 0; i < nEntities; i++){
        a[i] = *SHPReadObject(handle,i);
        recognition_result = env->NewObject(
                shpObjectClass, shpObjectConstructor, a[i].nSHPType, a[i].nParts, *a[i].panPartStart, *a[i].padfX, *a[i].padfY);
    ...
    }

Sadly when executing this code my application close. Although when i change my constructor in java, and method signature in c++ to:

public SHPObject(int nSHPType, int nParts, int[] panPartStart)

methodID shpObjectConstructor = env->GetMethodID(shpObjectClass, "<init>", "(II[I)V");

everything work fine. So there is some problem in passing double[] variables. I cant figure out what is wrong. This is part of stack trace after executing this code (not really sure what part of it i should give, i dont notice anything refering to an error):

06-19 17:23:08.876 728-728/com.example.kaczor.tmc_shpreader W/dalvikvm: 
Invalid indirect reference 0xbcad9adc in decodeIndirectRef
06-19 17:23:08.876 728-728/com.example.kaczor.tmc_shpreader E/dalvikvm: VM 
aborting
06-19 17:23:08.906 728-728/com.example.kaczor.tmc_shpreader A/libc: Fatal 
signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 728 (r.tmc_shpreader)
[...]

Edit: C++ SHPObject definition can be find at: http://shapelib.maptools.org/shp_api.html

2

1 Answer 1

1

So i've converted double[] to jdoubleArray, not sure why i didn't have to convert int[]. Although i found out that all values of int[] in Java were 0, so i have to convert it anyway.

    jclass shpObjectClass = env->FindClass("com/example/kaczor/tmc_shpreader/Shape/Shapes/SHPObject");
    jmethodID shpObjectConstructor = env->GetMethodID(shpObjectClass, "<init>", "(IIIIIII[I[D[D)V");
    SHPObject* a = new SHPObject[nEntities];
    jobject recognition_result;
    jobjectArray shapesToReturn = env->NewObjectArray(nEntities,shpObjectClass,env->NewObject(shpObjectClass,defaultShpObjectConstructor));

    for(i = 0; i < nEntities; i++){
        a[i] = *SHPReadObject(handle,i);

        jdoubleArray padfXARRAY = env->NewDoubleArray(a[i].nVertices);
        env->SetDoubleArrayRegion(padfXARRAY, 0, a[i].nVertices, (jdouble *)a[i].padfX );
        jdoubleArray padfYARRAY = env->NewDoubleArray(a[i].nVertices);
        env->SetDoubleArrayRegion(padfYARRAY, 0, a[i].nVertices, (jdouble *)a[i].padfY );
jdoubleArray panPartStart = env->NewDoubleArray(a[i].nParts);
        env->SetDoubleArrayRegion(panPartStart, 0, a[i].nParts, (jdouble *)a[i].panPartStart );

        int shapeId = a[i].nShapeId;
        int shpType = a[i].nSHPType;
        int nParts = a[i].nParts;
        int dfXMin = a[i].dfXMin;
        int dfXmax = a[i].dfXMax;
        int dfYMax = a[i].dfYMax;
        int dfYMin = a[i].dfYMin;

        recognition_result = env->NewObject(
                        shpObjectClass, shpObjectConstructor, shapeId,shpType,nParts,dfXMin,dfXmax,dfYMin,dfYMax,panPartStart, padfXARRAY, padfYARRAY);
        env->DeleteLocalRef(padfXARRAY);
        env->DeleteLocalRef(padfYARRAY);
        env->SetObjectArrayElement(shapesToReturn,i,recognition_result);
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.