I'm trying to get a string from sharedPreferences on Android from C++ code using JNI. I can successfully get the MethodID for getBoolean with this code:
jmethodID getBooleanMethodID = JEnv->GetMethodID(sharedPreferencesClass, "getBoolean", "(Ljava/lang/String;Z)Z");
The getBoolean function is defined in Java as getBoolean(String key, boolean defValue)
But I can't figure out how to correctly format the GetMethodID arguments for getString. The getString function is defined in Java as getString(String key, String defValue)
I've tried:
jmethodID getStringMethodID = JEnv->GetMethodID(sharedPreferencesClass, "getString", "(Ljava/lang/String;Ljava/lang/String)");
Can someone provide the correct way to format the argument param for getString?
The correct format turned out to be:
jmethodID getStringMethodID = JEnv->GetMethodID(sharedPreferencesClass, "getString", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
There were a couple issues with my original attemps. First, the second String arg inside the brackets needed a semi-colon. Then I needed to add the return type, also a String, and be sure that it had a semi-colon at the end too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.