Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JNI方法返回点的ArrayList时出错 我试图使用JNI导入一个C++库,我将在java项目中使用它。我已经成功地获得了要调用的库方法,并且正在尝试从JNI函数返回点对象的ArrayList。然而,我得到了一个描述相当模糊的错误(“有问题的框架: V[libjvm.dylib+0x30bab5]JNI_ArgumentPusherVaArg::JNI_ArgumentPusherVaArg(_jmethodID*,_va_list_tag*)+0xd '). 我不知道发生了什么,有人知道发生了什么或者我应该如何解释这个控制台输出吗?如果有人需要,我可以附加日志文件_Java_C++_Arraylist_Java Native Interface - Fatal编程技术网

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

JNI方法返回点的ArrayList时出错 我试图使用JNI导入一个C++库,我将在java项目中使用它。我已经成功地获得了要调用的库方法,并且正在尝试从JNI函数返回点对象的ArrayList。然而,我得到了一个描述相当模糊的错误(“有问题的框架: V[libjvm.dylib+0x30bab5]JNI_ArgumentPusherVaArg::JNI_ArgumentPusherVaArg(_jmethodID*,_va_list_tag*)+0xd '). 我不知道发生了什么,有人知道发生了什么或者我应该如何解释这个控制台输出吗?如果有人需要,我可以附加日志文件,java,c++,arraylist,java-native-interface,Java,C++,Arraylist,Java Native Interface,控制台输出: # # 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)

控制台输出:

#
# 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;
}
/*
* HPAProgram。C++
*
*创建日期:2014年2月4日
*作者:zalbhathena
*/
//=#包括
#包括
#包括“HPA程序h”
#包括“DCDTWrapper.h”
JNIEXPORT作业对象JNICALL Java_HPAProgram_sayHello(JNIEnv*env,作业对象){
printf(“你好,世界!\n”);
阵列边缘;
创建_dcdt(边和边);
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_类,“,”()V”);
jmethodID init_point=(*env).GetMethodID(point_class,”,“(II)V”);
jmethodID add_arraylist=(*env).GetMethodID(arraylist_类,“add”,“(java/lang/Object)V”);
jobject return_obj=(*env).NewObject(arraylist_类,init_arraylist);
printf(“2\n”);
对于(int n=0;n0:移动多边形
void create_dcdt(GsArray*边)
{
printf(“ASDF”);
const double*data=CurExample;
gspol;
//域:
while(*data!=END){pol.push().set((float)data[0],(float)data[1]);data+=2;}
theddt.init(pol,0.00001f);
而(*++数据!=结束)
{pol.size(0);
while(*data!=END){pol.push().set((float)data[0],(float)data[1]);data+=2;}
插入多边形(pol);
}
gstr;
theddt.get_mesh_edges(edges,&unsectr);
对于(int i=0;i推送(取消传输获取(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();        
    }
}
import java.util.ArrayList;
公共类HPA程序{
/*静止的{
//System.out.println(新文件(“.”.getAbsolutePath());
System.loadLibrary(“libhpaprogram”);//hello.dll(Windows)或libhello.so(Unix)
}
//私有本机void sayHello();
*/  
公共本机ArrayList sayHello();
公共静态void main(字符串[]args){
系统加载库(“HPA程序”);
HPA程序s=新的HPA程序();
s、 你好;
MapWindowController映射=新的MapWindowController();
}
}

函数
add
from class
ArrayList
具有返回类型
boolean
而不是
void
,因此在c代码中,您必须从env调用
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");
jmethodID add_arraylist = (*env).GetMethodID(arraylist_class, "add", "(java/lang/Object)V");