@@ -63,10 +63,15 @@ jint JNI_OnLoad(JavaVM * jvm, void * reserved)
63
63
ChipLogProgress (Test, " Loading Java class references." );
64
64
65
65
// Get various class references need by the API.
66
- err = JniReferences::GetInstance ().GetClassRef (env, " com/tcl/chip/chiptest/TestEngine" , sTestEngineCls );
66
+ jobject testEngineCls;
67
+ err = JniReferences::GetInstance ().GetLocalClassRef (env, " com/tcl/chip/chiptest/TestEngine" , sTestEngineCls );
67
68
SuccessOrExit (err);
68
-
69
- err = JniReferences::GetInstance ().GetClassRef (env, " com/tcl/chip/chiptest/TestEngineException" , sTestEngineExceptionCls );
69
+ err = sTestEngineCls .Init (testEngineCls);
70
+ SuccessOrExit (err);
71
+ jobject testEngineExceptionCls;
72
+ err = JniReferences::GetInstance ().GetLocalClassRef (env, " com/tcl/chip/chiptest/TestEngineException" , sTestEngineExceptionCls );
73
+ SuccessOrExit (err);
74
+ err = sTestEngineExceptionCls .Init (testEngineExceptionCls);
70
75
SuccessOrExit (err);
71
76
ChipLogProgress (Test, " Java class references loaded." );
72
77
@@ -141,7 +146,7 @@ CHIP_ERROR N2J_Error(JNIEnv * env, CHIP_ERROR inErr, jthrowable & outEx)
141
146
jmethodID constructor;
142
147
143
148
env->ExceptionClear ();
144
- constructor = env->GetMethodID (sTestEngineExceptionCls , " <init>" , " (ILjava/lang/String;)V" );
149
+ constructor = env->GetMethodID (sTestEngineExceptionCls . ObjectRef () , " <init>" , " (ILjava/lang/String;)V" );
145
150
VerifyOrExit (constructor != NULL , err = CHIP_JNI_ERROR_METHOD_NOT_FOUND);
146
151
147
152
switch (inErr.AsInteger ())
@@ -164,7 +169,8 @@ CHIP_ERROR N2J_Error(JNIEnv * env, CHIP_ERROR inErr, jthrowable & outEx)
164
169
}
165
170
errStrObj = (errStr != NULL ) ? env->NewStringUTF (errStr) : NULL ;
166
171
167
- outEx = (jthrowable) env->NewObject (sTestEngineExceptionCls , constructor, static_cast <jint>(inErr.AsInteger ()), errStrObj);
172
+ outEx = (jthrowable) env->NewObject (sTestEngineExceptionCls .ObjectRef (), constructor, static_cast <jint>(inErr.AsInteger ()),
173
+ errStrObj);
168
174
VerifyOrExit (!env->ExceptionCheck (), err = CHIP_JNI_ERROR_EXCEPTION_THROWN);
169
175
170
176
exit :
@@ -184,7 +190,7 @@ static void onLog(const char * fmt, ...)
184
190
JNIEnv * env = JniReferences::GetInstance ().GetEnvForCurrentThread ();
185
191
VerifyOrExit (env != NULL , err = CHIP_JNI_ERROR_NO_ENV);
186
192
187
- method = env->GetStaticMethodID (sTestEngineCls , " onTestLog" , " (Ljava/lang/String;)V" );
193
+ method = env->GetStaticMethodID (sTestEngineCls . ObjectRef () , " onTestLog" , " (Ljava/lang/String;)V" );
188
194
VerifyOrExit (method != NULL , err = CHIP_JNI_ERROR_NO_ENV);
189
195
190
196
va_start (args, fmt);
@@ -195,7 +201,7 @@ static void onLog(const char * fmt, ...)
195
201
ChipLogProgress (Test, " Calling Java onTestLog" );
196
202
197
203
env->ExceptionClear ();
198
- env->CallStaticVoidMethod (sTestEngineCls , method, strObj);
204
+ env->CallStaticVoidMethod (sTestEngineCls . ObjectRef () , method, strObj);
199
205
VerifyOrExit (!env->ExceptionCheck (), err = CHIP_JNI_ERROR_EXCEPTION_THROWN);
200
206
201
207
exit :
0 commit comments