Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JNA, Structures and Arrays

I'm trying to create a array of my class (that extends JNA's Structure) to pass it for a DLL function. I have the values readed from a database to a ArrayList, and now I need to put them into a array. First, I tried to use the toArray() method of ArrayList, but it return me the following exception when I call the native function:

java.lang.IllegalArgumentException: Structure array elements must use contiguous memory (bad backing address at Structure array index 1)

If I simply set a new array with the same size as the ArrayList, when I will set the 'fields' of the struct in my class, it returns me a NullPointerException.

Someone can help me to solve this?

like image 259
Rafael Toledo Avatar asked Nov 05 '22 03:11

Rafael Toledo


1 Answers

Structure.toArray() provides you with a block of contiguously allocated Structure objects. Create this array of Structure prior to initializing it from your ArrayList of "values".

like image 101
technomage Avatar answered Nov 09 '22 11:11

technomage