dcsimg
What's wrong?
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jeffrey_rui
Posted On:   Monday, July 22, 2002 02:15 AM

In cpp side line written in bold font,i can only get NULL! Java side public class compiler { &nbsp pubic myfunc func=new myfunc(); &nbsp&nbsp class myfunc{ &nbsp&nbsp&nbsp&nbsp int m_iParamNum; &nbsp&nbsp } &nbsp&nbsp static { &nbsp&nbsp&nbsp&nbsp System.loadLibrary("compiler"); &nbsp&nbsp } &nbsp&nbspstatic public native Cfunction SE_GetPFunctionTable(); &nbsp&nbsp public compiler() { &nbsp&nbsp } } C side JNIEXPORT    More>>

In cpp side line written in bold font,i can only get NULL!

Java side

public class compiler {

&nbsp pubic myfunc func=new myfunc();


&nbsp&nbsp class myfunc{

&nbsp&nbsp&nbsp&nbsp int m_iParamNum;

&nbsp&nbsp }

&nbsp&nbsp static {

&nbsp&nbsp&nbsp&nbsp System.loadLibrary("compiler");

&nbsp&nbsp }


&nbsp&nbspstatic public native Cfunction SE_GetPFunctionTable();

&nbsp&nbsp public compiler() {

&nbsp&nbsp }

}



C side

JNIEXPORT jobject JNICALL Java_compiler_SE_1GetPFunctionTable
(JNIEnv *, jclass);

{


&nbsp&nbsp static jfieldID funcTableID=NULL;

&nbsp&nbsp jobject resu;

&nbsp&nbsp jclass cls = env->GetObjectClass(obj);

&nbsp&nbsp funcTableID=env->GetFieldID(cls, "func", "java/lang/Object");

&nbsp&nbsp resu=env->GetObjectField(obj,funcTableID);


&nbsp&nbsp static jfieldID lineID=NULL;

&nbsp&nbsp jclass cfunctbl=env->GetObjectClass(resu);

&nbsp&nbsp lineID=env->GetFieldID(cfunctbl,"m_iParamNum","I");

&nbsp&nbsp jint setline=100;

&nbsp&nbsp env->SetIntField(obj,lineID,setline);


&nbsp&nbsp return resu;


}

   <<Less

Re: What's wrong?

Posted By:   Alexander_Krapf  
Posted On:   Tuesday, July 23, 2002 04:26 PM

Jeffrey,


Assuming that you actually have a field named "func" and having a declared type of Object, you need to use the correct JNI lookupname for the type as in:



funcTableID = env->GetFieldID( cls, "func", "Ljava/lang/Object;" );

If you want to waste less time and end up with more reliable software, you should check out www.codemesh.com for a very mature code generator that takes Java classes as input and generates C++ proxy classes that would allow you to write something like:



compiler::func = 100;

Much nicer and much easier to maintain.


Hope this helps,


Alex

Re: What's wrong?

Posted By:   Roy_G  
Posted On:   Tuesday, July 23, 2002 08:32 AM

The meaning of the line "funcTableID=env->GetFieldID(cls, "func", "java/lang/Object"); " is to get the a field called func in the class java.lang.Object.

If you have created a class "MyClass" and you want the field myField in it

you shuod write :

funcTableID=env->GetFieldID(cls, "myField", "com.Path.MyClass");

hope it works

Re: What's wrong?

Posted By:   Otto_Fowler  
Posted On:   Monday, July 22, 2002 03:16 AM

Does java/lang/Object" have a func?
if not you may need to ask for the right class.
About | Sitemap | Contact