Click here to Skip to main content
15,557,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to pass a string value from java to c. And, a hashmap from C to java. I am trying to pass this using same method in C. But, I can't do that in a same method. I need the string data to fill my hashmap. So, I need to do it inside a single method. If I fill the hashmap(filling data locally) from C, it passes.

What I have tried:

Is it possible to pass data back and forth using the same method in C?
Posted
Updated 24-Jun-21 2:50am
v5
Comments
Richard MacCutchan 24-Jun-21 6:11am    
Impossible to guess since we have no idea what your code is actually doing. Passing data between C and Java via JNI is quite straightforward, as long as you follow the rules.
15160877 24-Jun-21 6:39am    
I want to pass string to function(in C) which returns jobject.
public static native HashMap<string, string> displayString(java.lang.String value);
public static native HashMap<string, string> displayString();

I declared the native methods in java as above. The problem is C is not accepting the string and pass the hashmap at the same time.

My c function is like this:
JNIEXPORT jobject JNICALL Java_JavaNative_displayString(JNIEnv* env, jclass obj, jstring str) {
return jobject;
}
Richard MacCutchan 24-Jun-21 7:08am    
vv
15160877 24-Jun-21 7:11am    
jobject is a hashmap. It works fine, that is why I didn't add the code. My c code reads the file,add it to hashmap and then returns it.
Richard MacCutchan 24-Jun-21 7:18am    
So what exactly is the problem?

1 solution

I have checked the JNI Documentation[^] and cannot see any support for HashMaps. You will need to use one of the supported types.
 
Share this answer
 
Comments
15160877 24-Jun-21 7:51am    
Problem solved!!! Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900