How to create an ArrayList and add element with Rust JNI?

⚓ rust    📅 2025-06-16    👤 surdeus    👁️ 3      

surdeus

Hello,
Is it possible to create an collection ArrayList and append object?

I tried to do smth like a:

let cls_array_list = jenv.find_class("java/util/ArrayList").unwrap();
let items_list = jenv.new_object(cls_array_list, "()V", &[]).unwrap();

then add item

let cls_item = jenv.find_class("Item").unwrap();
let obj_item = jenv.new_object(cls_item, "()V", &[]).unwrap();

jenv.call_method(
    &items_list,
    "add",
    "(Ljava/lang/Object;)V",
    &[JValue::Object(&item1)],
)
.unwrap();

But got exception:

Exception in thread "Thread-0" java.lang.NoSuchMethodError: Ljava/util/ArrayList;.add(Ljava/lang/Object;)V

Any ideas how can I create collection of Items?
Thanks!

5 posts - 2 participants

Read full topic

🏷️ rust_feed