MReza MReza - 2 months ago 16x
Android Question

SetDataAndType method

As documented in Android Developers page setDataAndType method can be called in this way:

auto setDataAndTypeFunctionId = env->GetMethodID(intentClassId, "setDataAndType", "(Landroid/net/Uri;Ljava/lang/String;)V");
jstring jmime = env->NewStringUTF("video/*");
env->CallVoidMethod(context, setDataAndTypeFunctionId, intentObject, UriObject, jmime);

But when i run my app this error show on output:

java.lang.NoSuchMethodError: no method with name='setDataAndType' signature='(Landroid/net/Uri;Ljava/lang/String;)V' in class Landroid/content/Intent;


The problem is the return type, which is not void. The setDataAndType method returns an object of type Intent.

Use the following signature:

env->GetMethodID(intentClassId, "setDataAndType", "(Landroid/net/Uri;Ljava/lang/String;)Landroid/content/Intent;");

Also, you should use CallObjectMethod instead of CallVoidMethod, although it doesn't really matter because you're not using the return value.