简体   繁体   English

JNI 在应用程序中检测到错误:为内部类调用 NewObject 时使用无效的作业

[英]JNI DETECTED ERROR IN APPLICATION: use of invalid jobject when calling NewObject for innerclass

This is how my java file looks like:这是我的 java 文件的样子:

public class MyActivity
  {
            public class MyVector
            {
                public float X;
                public float Y;
                public float Z;

                public MyVector()
                {
                    this.X = 0.0f;
                    this.Y = 0.0f;
                    this.Z = 0.0f;
                }

                public MyVector(float InX,float InY, float InZ)
                {
                    this.X = InX;
                    this.Y = InY;
                    this.Z = InZ;
                }

                public void SetMyVector(float InX,float InY, float InZ)
                {
                    X = InX;
                    Y = InY;
                    Z = InZ;
                }               
            }
  }

This is how my cpp method looks like:这是我的 cpp 方法的样子:

static auto MyVectorClassID = env->FindClass("com/example/Test/MyActivity$MyVector");

static auto MyVectorParamCtorID = env->GetMethodID(MyVectorClassID, "<init>", "(Lcom/example/Test/MyActivity;FFF)V");

MyVector SomeVector{ 10.0f, 10.0f, 10.0f };

jfloat FloatX = SomeVector.X;
jfloat FloatY = SomeVector.Y;
jfloat FloatZ = SomeVector.Z;

auto jObj = env->NewObject(MyVectorClassID, MyVectorParamCtorID, FloatX, FloatY, FloatZ); // Crashes my android device here.

In my cpp code i have a struct named as MyVector similar to java class MyVector.在我的 cpp 代码中,我有一个名为 MyVector 的结构,类似于 java 类 MyVector。 I just don't know what i am doing wrong here.我只是不知道我在这里做错了什么。

It is giving me JNI DETECTED ERROR IN APPLICATION: use of invalid jobject 0xd18a1c78 when env->NewObject is called.它给了我JNI DETECTED ERROR IN APPLICATION: use of invalid jobject 0xd18a1c78 when env->NewObject is called.

Thank you.谢谢你。

Thank you, @Botje, @Petesh and @Seelenvirtuose, your answers helped me understand working with inner classes in JNI.谢谢@Botje、@Petesh 和@Seelenvirtuose,您的回答帮助我理解在 JNI 中使用内部类。 I am new to this.我是新来的。

The way i fixed my problem was, i followed the answer in this link In JNI, how do I cache the class, methodID, and fieldIDs per IBM's performance recommendations?我解决问题的方法是,我按照此链接中的答案在 JNI 中,如何根据 IBM 的性能建议缓存类、方法 ID 和字段 ID? shared by @Petesh and made a global reference for the ID's of my inner class MyVector and also for my outer class MyActivity.由@Petesh 共享,并为我的内部类 MyVector 和外部类 MyActivity 的 ID 做了一个全局引用。

So, for creating an object of inner class, this is what i had to do.所以,为了创建内部类的对象,这就是我必须做的。

auto jObj = env->NewObject(InnerClassID, InnerClassConstructorID, OuterclassObject, Params);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何调试:应用程序中的JNI检测到错误:使用无效的jobject - How to debug: JNI DETECTED ERROR IN APPLICATION: use of invalid jobject JNI在应用程序中检测到错误:使用已删除的本地引用0x1 - JNI DETECTED ERROR IN APPLICATION: use of deleted local reference 0x1 JNI检测到应用程序错误:使用已删除的弱全局引用 - JNI DETECTED ERROR IN APPLICATION: use of deleted weak global reference 为什么调用CallStaticVoidMethod会将无效的jobject与JNI一起使用 - Why called CallStaticVoidMethod throwed use of invalid jobject with JNI Android(ART)崩溃,错误JNI DETECTED ERROR IN APPLICATION:jarray是无效的堆栈间接引用表或无效的引用 - Android (ART) crash with error JNI DETECTED ERROR IN APPLICATION: jarray is an invalid stack indirect reference table or invalid reference Android(ART)崩溃,错误JNI DETECTED ERROR IN APPLICATION:jstring是无效的本地引用 - Android (ART) crash with error JNI DETECTED ERROR IN APPLICATION: jstring is an invalid local reference Brother SDK 调用 PrintImage 导致 JNI DETECTED ERROR IN APPLICATION: GetStringUTFChars received NULL jstring - Brother SDK Calling PrintImage causes JNI DETECTED ERROR IN APPLICATION: GetStringUTFChars received NULL jstring JNI在Brother SDK上的应用程序中检测到错误 - JNI DETECTED ERROR IN APPLICATION on Brother SDK Android JNI 在应用程序中检测到错误:调用 JNI GetMethodID 时出现未决异常 - Android JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception 如何使用Jobject数组? (Jni) - How to use a jobject array ? (Jni)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM