JNA, structures and arrays

I am trying to create an array of my class (which extends the JNA structure) to pass it to a DLL function. I have values ​​that are read from a database in an ArrayList, and now I need to put them in an array. First, I tried using the ArrayL (ArrayList) method, but it returns 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 just set up a new array with the same size as ArrayList, when I set the β€œfields” of the structure in my class, it will return a NullPointerException to me.

Can anyone help me solve this problem?

+4
source share
1 answer

Structure.toArray () provides you with a block of adjacent distributed Structure objects. Create this structure array before initializing it from an ArrayList of "values".

+2
source

Source: https://habr.com/ru/post/1401246/


All Articles