- Home /
JNI error when calling Java plugin from System.AppDomain.CurrentDomain.UnhandledException callback handler
Hello everyone, when I try to access my Java plugin from application's unhandled exception callback I'm getting the following errors and my application freezes:
JNI ERROR (app bug): accessed stale Local 0x9 (index 0 in a table of size 0)
JNI DETECTED ERROR IN APPLICATION: use of deleted local reference 0x9
Here is my C# script, attached to one of the game objects:
using UnityEngine;
using System.Threading;
using System;
public class PlayerController : MonoBehaviour
{
void Start()
{
AppDomain.CurrentDomain.UnhandledException += OnHandleUnresolvedException;
using (var javaClass = new AndroidJavaClass("MyJavaClass"))
{
var str = javaClass.CallStatic<string>("GetString");
Debug.Log("String from Java class: " + str);
}
new Thread(() =>
{
Thread.Sleep(10000);
object obj = null;
obj.ToString();
}).Start();
}
private static void OnHandleUnresolvedException(object sender, UnhandledExceptionEventArgs e)
{
var message = ((Exception)e.ExceptionObject).Message;
Debug.Log("Unhandled exception: " + message);
using (var javaClass = new AndroidJavaClass("MyJavaClass"))
{
javaClass.CallStatic("ErrorOccurred", message);
}
}
}
And here is the Java plugin source code. It is added to Unity project as a simple ".java" file in the assets folder, plugin import settings are correctly configured ("Android" checkbox checked):
import android.util.Log;
public class MyJavaClass
{
public static void ErrorOccurred(String message)
{
Log.e("TAG", message);
}
public static String GetString()
{
return "test";
}
}
When I start my application on Android emulator I see the following messages in the Logcat window:
I/Unity: String from Java class: test
I/Unity: Unhandled exception: Object reference not set to an instance of an object
E/zygote: JNI ERROR (app bug): accessed stale Local 0x9 (index 0 in a table of size 0)
A/zygote: java_vm_ext.cc:534] JNI DETECTED ERROR IN APPLICATION: use of deleted local reference 0x9
Any tips will be greatly appreciated!
Your answer
Follow this Question
Related Questions
Now that Unity 4.1.2 broke the Android plugin examples, what do you use to learn them? 1 Answer
in callJavaCode JNI example, question about JNI_OnLoad 0 Answers
Boat script problems when changing platform to android 0 Answers
ERROR: SoomlaStore failure: IabActivity is destroyed during purchase. 0 Answers
script error missingfeildexception 1 Answer