Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help on using NewObject with constructors!

843829Feb 25 2006 — edited Feb 26 2006
Hi,All:

I want to create an object in a native method. The object is an instance of an inner class. The inner class has two constructors: one default and one with two arguments. There is no problem if I use NewObject with the default construtor. But if I use NewObject with the constructor taking two int arguments. The JVM crashes.

Can anybody give me some idea what the problem is?

Thanks!

Tao

Here is the native method, the inner class and error message:

JNIEXPORT jobject JNICALL Java_Prompt_createtp(JNIEnv *env, jobject obj)
{
jobject test_ttt= 0;
jclass cls2;
jmethodID cid;
jint a,b;
jfieldID fid;

a = 10; b = 20;

cls2 = (*env)->FindClass(env,"LPrompt$tp;");
cid = (*env)->GetMethodID(env,cls2,"<init>","(LPrompt;II)V");
test_ttt = (*env)->NewObject(env,cls2,cid,a,b);

// However, the following codes using default constructor works well
//cid = (*env)->GetMethodID(env,cls2,"<init>","(LPrompt;)V");
//test_ttt = (*env)->NewObject(env,cls2,cid);

(*env)->DeleteLocalRef(env,cls2);
return test_ttt;

}

// here is the inner class
class tp{

int a;
int b;

tp(){
a = 100;
b = 0;
}

tp(int x,int y){
a = x; b = y;
}

}


#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# Internal Error (53484152454432554E54494D450E43505001A3), pid=276, tid=640
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode)
# An error report file with more information is saved as hs_err_pid276.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 26 2006
Added on Feb 25 2006
4 comments
563 views