It seems like keyCount
is to low of a number, or maybe even zero.
If you don't know how many key are going to be in an array, initialize the String[]
array with a number larger than zero. Then, as you add more items, make sure keys.length()
is large enough to accept a new item. If not, use Arrays.copyOf()
to increase its size. Check out the Javadoc for the function here
Also, you can use a higher level array, like ArrayList
. This will ensure you never add more items than the array can handle, by performing the copyOf()
method internally automatically.
Such as:
ArrayList<String> keys = new ArrayList<String>(keyCount); //keyCount gives no. of keys in lmdb tree
int count=0;
cursor.first(); //to move to first position
while(cursor.next){
keys.add(cursor.keyUtf8(0).getString().toString()); //getting error in this line it's working for reading values.
count++l
}