why NewObject return NULL?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   fjhst_fjhst
Posted On:   Wednesday, June 11, 2003 10:47 AM

Hi all, I have a native C++ function that supposedly get a new Object: //define: struct JavaStruct { char *JvmPath; char *JavaClassPath; JNIEnv *env; JavaVM *jvm; char *SampleClassName; char *SampleMethodName; jclass SampleClass; jmethodID SampleMethod; }; int LoadSampleMethod(struct JavaStruct *pJavaStruct) { jthrowable exc; jclass j_string; jclass loaderClass; char infor[255], *buffer; char *FileName = "E:\JAVA\JniApp\HelloWorld.class"; if(pJavaStruct->jvm == NULL || pJavaStruct->env == NULL) return -1; TFileStream *FileStream = new TFileSt   More>>
			
Hi all,

I have a native C++ function that supposedly get a new Object:

//define:

struct JavaStruct
{
char *JvmPath;
char *JavaClassPath;
JNIEnv *env;
JavaVM *jvm;
char *SampleClassName;
char *SampleMethodName;
jclass SampleClass;
jmethodID SampleMethod;
};

int LoadSampleMethod(struct JavaStruct *pJavaStruct)
{
jthrowable exc;
jclass j_string;
jclass loaderClass;
char infor[255], *buffer;
char *FileName = "E:\JAVA\JniApp\HelloWorld.class";

if(pJavaStruct->jvm == NULL || pJavaStruct->env == NULL) return -1;

TFileStream *FileStream = new TFileStream(FileName, fmOpenRead);
buffer = (char *)malloc(FileStream->Size+2);
FileStream->Read(buffer, FileStream->Size);

loaderClass = pJavaStruct->env->FindClass("java/lang/ClassLoader");
jmethodID loaderMID = pJavaStruct->env->GetMethodID(loaderClass, " ", "()V");
if (loaderClass == NULL || loaderMID == NULL) return -1;

jclass clazz = pJavaStruct->env->GetObjectClass(loaderClass);
jobject loaderObj = pJavaStruct->env->NewObject(clazz, loaderMID);
if (loaderObj == NULL) return -2;

pJavaStruct->SampleClass = pJavaStruct->env->DefineClass(pJavaStruct->SampleClassName,
loaderObj, buffer, FileStream->Size);

if( pJavaStruct->SampleClass != 0 )
{
pJavaStruct->SampleMethod = pJavaStruct->env->GetStaticMethodID
(
pJavaStruct->SampleClass,
pJavaStruct->SampleMethodName,
"([Ljava/lang/String;)V"
);
}else
{
return -3;
}

free(buffer);
FileStream->Free();

return 0;
}


int _export _stdcall InitJavaStruct(struct JavaStruct *pJavaStruct)
{
LoadJavaVirtualMachineBcb(pJavaStruct);

...

LoadSampleMethod(pJavaStruct);

...

return 0;
}


when debugged, in the LoadSampleMethod fuction, the values of clazz and loaderMID
look like valid(not null), but why NewObject return NULL? what problem happen?
   <<Less
About | Sitemap | Contact