【问题标题】:Error in JNI method returning ArrayList of PointsJNI 方法返回点的 ArrayList 时出错
【发布时间】:2014-02-07 22:06:20
【问题描述】:

我正在尝试使用 JNI 导入我将在我的 java 项目中使用的 c++ 库。我已成功获取要调用的库方法,并尝试从 JNI 函数返回 Point 对象的 ArrayList。但是,我收到一个描述相当模糊的错误('有问题的框架: V [libjvm.dylib+0x30bab5] JNI_ArgumentPusherVaArg::JNI_ArgumentPusherVaArg(_jmethodID*, __va_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();        
    }
}

【问题讨论】:

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


    【解决方案1】:

    函数 addfrom 类 ArrayList 具有返回类型 boolean 而不是 void 所以在 c 代码中你必须从 env 调用 CallBooleanMethod 而不是 CallVoidMethod

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

    【讨论】:

      【解决方案2】:

      您需要更改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");
      

      【讨论】:

        猜你喜欢
        • 2021-08-29
        • 2012-11-15
        • 2015-05-15
        • 2013-11-19
        • 1970-01-01
        • 2014-04-23
        • 1970-01-01
        • 2015-01-29
        • 1970-01-01
        相关资源
        最近更新 更多