JNI方法返回Points的ArrayList时出错

时间:2014-02-07 22:06:20

标签: java c++ arraylist java-native-interface

我正在尝试使用JNI导入我将在我的java项目中使用的c ++库。我已成功获取要调用的库方法,并尝试从JNI函数返回Point对象的ArrayList。但是,我收到一个错误的描述相当模糊('有问题的框架:  V [libjvm.dylib + 0x30bab5] JNI_ArgumentPusherVaArg :: JNI_ArgumentPusherVaArg(_jmethodID *,__ ev_list_tag *)+ 0xd “)。我不知道发生了什么,有谁知道发生了什么或者我应该如何解释这个控制台输出?如果有人想要,我可以附加日志文件。

控制台输出:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x000000010550bab5, pid=4633, tid=6403
#
# JRE version: Java(TM) SE Runtime Environment (7.0_51-b13) (build 1.7.0_51-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.51-b03 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# V  [libjvm.dylib+0x30bab5]  JNI_ArgumentPusherVaArg::JNI_ArgumentPusherVaArg(_jmethodID*, __va_list_tag*)+0xd
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/zalbhathena/Documents/workspace/Thesis-Test-Application/HPA* Program/hs_err_pid4633.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
#
Hello World!
ASDFse_dcdt.cpp 284 : Starting init()...
SeDcdt::initfoo.512se_dcdt.cpp 303 : Calculating External Polygon for domain with 4 points...
se_dcdt.cpp 317 : Creating External Polygon...
SeDcdt::initse_dcdt.cpp 326 : Backface v1: -14 -14
se_dcdt.cpp 329 : Backface v2: -14 14
se_dcdt.cpp 332 : Backface v3: 14 14
se_dcdt.cpp 335 : Backface v4: 14 -14
se_triangulator.cpp 417 : insert_point_in_edge...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...4
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 387 : insert_point_in_face...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...3
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 417 : insert_point_in_edge...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...4
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 387 : insert_point_in_face...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...3
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 417 : insert_point_in_edge...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...4
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 387 : insert_point_in_face...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...3
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 387 : insert_point_in_face...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...3
se_triangulator.cpp 538 : Ok.
1
2
3
4

HPAProgram.cpp

/*
 * HPAProgram.c++
 *
 *  Created on: Feb 4, 2014
 *      Author: zalbhathena
 */

//=#include <jni.h>
#include <stdio.h>
#include "HPAProgram.h"
#include "DCDTWrapper.h"


JNIEXPORT jobject JNICALL Java_HPAProgram_sayHello (JNIEnv *env, jobject obj) {
   printf("Hello World!\n");
   GsArray<GsPnt2> edges;
   create_dcdt(&edges);

   printf("1\n");
   jclass arraylist_class = (*env).FindClass("java/util/ArrayList");
   jclass point_class = (*env).FindClass("java/awt/Point");

   jmethodID init_arraylist = (*env).GetMethodID(arraylist_class, "<init>", "()V");
   jmethodID init_point = (*env).GetMethodID(point_class, "<init>", "(II)V");
   jmethodID add_arraylist = (*env).GetMethodID(arraylist_class, "add", "(java/lang/Object)V");

   jobject return_obj = (*env).NewObject(arraylist_class, init_arraylist);

   printf("2\n");
   for (int n=0;n<edges.size();n++)
   {

       jfloat x = 1;
       jfloat y = 1;
       printf("3\n");
       jobject point_obj = (*env).NewObject(point_class, init_point,x,y);
       printf("4\n");
       (*env).CallVoidMethod(return_obj, add_arraylist, point_obj);
       printf("5\n");

   }
   return nullptr;
}

DCDTWrapper.cpp

# define END 12345.6
# define FIRST_EXAMPLE  Example1
//# include "DCDTsrc/se_dcdt.h"
//# include "DCDTsrc/gs_polygon.h"
//# include <stdlib.h>
# include "DCDTWrapper.h"

static double Example1[] =
       { -10, -10, 10, -10, 10, 10, -10, 10, END,
           1, 1, 7, 3, 3, 8, END,
         END };

static const double* CurExample = FIRST_EXAMPLE;
static SeDcdt TheDcdt;
static GsPolygon CurPath;
static GsPolygon CurChannel;
static float CurX1=0, CurY1=0, CurX2=0, CurY2=0;
static int   CurSelection=0; // -2,-1: moving point, >0: moving polygon


void create_dcdt (GsArray<GsPnt2>* edges)
 {
    printf("ASDF");
   const double* data = CurExample;
   GsPolygon pol;

   // domain:
   while ( *data!=END ) { pol.push().set((float)data[0],(float)data[1]); data+=2; }
   TheDcdt.init ( pol, 0.00001f );

   while ( *++data!=END )
    { pol.size(0);
      while ( *data!=END )  { pol.push().set((float)data[0],(float)data[1]); data+=2; }
      TheDcdt.insert_polygon ( pol );
    }

   GsArray<GsPnt2> unconstr;

   TheDcdt.get_mesh_edges(edges, &unconstr);


   for(int i = 0; i < unconstr.size(); i++) {
       edges -> push(unconstr.get(i));
   }
 }

HPAProgram.java

import java.util.ArrayList;
public class HPAProgram {
/*  static {
        //System.out.println(new File(".").getAbsolutePath());
        System.loadLibrary("libhpaprogram"); // hello.dll (Windows) or libhello.so (Unixes)
    }
    //private native void sayHello();
    */  
    public native ArrayList<String> sayHello();
    public static void main(String[] args) {
        System.loadLibrary("HPAProgram");
        HPAProgram s = new HPAProgram();
        s.sayHello();
        MapWindowController map = new MapWindowController();        
    }
}

2 个答案:

答案 0 :(得分:0)

来自班级add的{​​{1}}函数的返回类型ArrayList而不是boolean,因此在c代码中,您必须从env调用void而不是{{1} }}

编辑:您还需要更正CallBooleanMethod方法的签名。

答案 1 :(得分:0)

您需要如下更改arrayList中“ add”元素的方法签名:

jmethodID add_arraylist = (*env).GetMethodID(arraylist_class, "add", "(java/lang/Object)Z"); 

代替

jmethodID add_arraylist = (*env).GetMethodID(arraylist_class, "add", "(java/lang/Object)V");