NewObject() fails
Hi all,
I have a very strange problem with JNI
when I call NewObject()
function the caller function returns immediately with no indication about what happens (exception or whatever).
the specification says that if the object can not be instantiated NULL should be returned! but this doesn't happen with me, I am completely unable to know what happens and make the caller function returns immadiately (I mean, the following lines aren't executed)
I also want to mention that the caller function is a callback which runs on another thread but I attached the thread to the VM using AttachCurrentThread()
function,
here a piece of my code
JNIEnv *jniEnv;
javaVM->AttachCurrentThread((void**)&jniEnv,NULL);
cout<<"thread attached"<<endl;
jclass remoteDeviceClass=jniEnv->FindClass("javax/bluetooth/RemoteDevice");
if(remoteDeviceClass==NULL)
cout<<"can not find class"<<endl;
else
cout><<"class found"<<endl;
jmethodID remoteDeviceConstructor=jniEnv->GetMethodID(remoteDeviceClass,"<init>","([BLjava/lang/String;)V");
if(remoteDeviceConstructor==NULL)
cout<<"can not find constructor"<<endl;
else
cout><<"constructor found"<<endl;
jobject remoteDevice=jniEnv->NewObject(remoteDeviceClass,remoteDeviceConstructor,convertAddressToJByteArray(bda),jniEnv->NewStringUTF((char*)bdName));// this line make the function return immediately with no exception or any indicator of the problem, the following lines are never executed.
if(remoteDevice==NULL)
cout<<"can not instantiate RemoteDevice"<<endl;
else
cout><<"RemoteDevice instantiated"<<endl;
cout><<"ok"<<endl;
jclass discoveryListenerClass=jniEnv->GetObjectClass(discoveryListener);
jmethodID deviceDiscovered=jniEnv->GetMethodID(discoveryListenerClass,"deviceDiscovered","(Ljavax/bluetooth/RemoteDevice;Ljavax/bluetooth/DeviceClass;)V");
jniEnv->CallVoidMethod(discoveryListener,deviceDiscovered,remoteDevice,NULL);
javaVM->DetachCurrentThread();
and I got output like that
thread attached
class found
constructor found
thanks in advance

