Checking errors and handling exceptions in JNI
JNI functions can fail because of system constraint (for example, lack of memory) or invalid arguments (for example, passing a native UTF-8 string when the function is expecting a UTF-16 string). This recipe discusses how to handle errors and exceptions in JNI programming.
The following recipes should be read first before proceeding with this recipe:
- Manipulating strings in JNI
- Managing references in JNI
- Accessing Java static and instance fields in native code
- Calling static and instance methods from native code
How to do it…
Follow these steps to create a sample Android project that illustrates errors and exception handling in JNI:
- Create a project named
ExceptionHandling. Set the package ...