Search code examples
javaandroidexceptionjava-native-interfacenosuchmethoderror

NoSuchMethodError in JNI to Java Exception


I am getting this error:

java.lang.NoSuchMethodError: no non-static method "Ljava/lang/AssertionError;.(Ljava/lang/String;)V"

jclass clazz = env->FindClass( "java/lang/AssertionError" );

env->ThrowNew( clazz, "Test Assertion" );

Note: env is JNIEnv*

Any thoughts? I see that AssertionError exists. I am seeing this on Android Lollipop only. It seems to be fine on android 4.4.2.


Solution

  • java.lang.AssertionError doesn't have the constructor mentioned in the error message. So you can't use ThrowNew(), which relies on that.

    You'll have to construct the exception yourself and use Throw().