返回数组点列表的 JNI 方法中的错误
Error in JNI method returning ArrayList of Points
我正在尝试使用 JNI 导入一个 c++ 库,我将在我的 java 项目中使用的库。我已经成功地调用了库方法,并正在尝试从 JNI 函数返回点对象的 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
HPAP图.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("1n");
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("2n");
for (int n=0;n<edges.size();n++)
{
jfloat x = 1;
jfloat y = 1;
printf("3n");
jobject point_obj = (*env).NewObject(point_class, init_point,x,y);
printf("4n");
(*env).CallVoidMethod(return_obj, add_arraylist, point_obj);
printf("5n");
}
return nullptr;
}
DCDT说唱歌手.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));
}
}
HPAP图.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();
}
}
来自类ArrayList
的函数add
具有返回类型boolean
不是void
所以在 C 代码中你必须从 env 而不是CallVoidMethod
调用CallBooleanMethod
。
编辑:您还需要更正add
方法的签名。
您需要更改 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");
相关文章:
- C++:正在检查LinkedList中的回文-递归方法-错误
- C++数组队列实现方法错误
- 方法错误"not all control paths return a value"和方法不返回值
- OpenGL 顶点缓冲区类重定义和模板方法错误
- 如何在 VC++ 中通过引用传递另一个对象的方法(错误 C2664)
- 复数程序编译时的计算方法错误
- CMake 构建错误 - 虚拟方法错误缺少 vtable
- 接受 lambda 作为参数的类方法 - 错误消息
- c++程序方法错误visualstudio
- OpenCV "findContours"方法错误
- std::线程类方法错误
- 基类没有新方法错误
- C++派生类继承方法错误
- 指向类方法错误c++11的指针数组
- 使用jni调用方法:错误的jni oop参数
- QVector.push_back方法错误
- 对静态方法错误的未定义引用
- Friend方法错误
- async_write方法错误
- 重写方法错误C++