从https://github.com/katchsvartanian/voiceRecognition导入。每当我在Android版本上运行项目时,Kitkat LogCat会出现以下错误:
JNI DETECTED ERROR IN APPLICATION: illegal class name 'com.example.jni.FLACStreamEncoder'
(should be of the form 'package/Class', [Lpackage/Class;' or '[[B')
in call to FindClass
from void com.example.jni.FLACStreamEncoder.init(java.lang.String, int, int, int)
在以下行显示错误:
init(outfile, sample_rate, channels, bits_per_sample)
在下面的函数中的FLACStreamEncoder.java中。
public FLACStreamEncoder(String outfile, int sample_rate, int channels,int bits_per_sample)
{
init(outfile, sample_rate, channels, bits_per_sample);
}
并在FLACRecorder.java中:
mEncoder = new FLACStreamEncoder (mPath, sample_rate, mapped_channels, mapped_format)
我的FLACStreamEncoder.cpp包含以下代码,我已更改:
static char const * const FLACStreamEncoder_classname="com.example.jni.FLACStreamEncoder";
到
static char const * const FLACStreamEncoder_classname="com/example/jni/FLACStreamEncoder";
当我在进行上述更改后运行代码并将光标移到错误上时
jclass cls = env->FindClass(FLACStreamEncoder_classname);
它显示提示为“jclass和jclass不兼容”。我不是很擅长C ++。我的FLACStreamEncoder.cpp包含以下代码。
...
static FLACStreamEncoder * get_encoder(JNIEnv * env, jobject obj)
{
assert(sizeof(jlong) >= sizeof(FLACStreamEncoder *));
// Do the JNI dance for getting the mObject field
jclass cls = env->FindClass(FLACStreamEncoder_classname);
jfieldID object_field = env->GetFieldID(cls, FLACStreamEncoder_mObject,"J");
jlong encoder_value = env->GetLongField(obj, object_field);
env->DeleteLocalRef(cls);
return reinterpret_cast<FLACStreamEncoder *>(encoder_value);
}
static void set_encoder(JNIEnv * env, jobject obj, FLACStreamEncoder * encoder)
{
assert(sizeof(jlong) >= sizeof(FLACStreamEncoder *));
// Do the JNI dance for setting the mObject field
jlong encoder_value = reinterpret_cast<jlong>(encoder);
jclass cls = env->FindClass(FLACStreamEncoder_classname);
jfieldID object_field = env->GetFieldID(cls, FLACStreamEncoder_mObject, "J");
env->SetLongField(obj, object_field, encoder_value);
env->DeleteLocalRef(cls);
}
...
我已在链接android art runtime check_jni.cc error on package name之后进行了更改。
我想知道的是,即使在更改类路径后,为什么它会显示相同的错误?
'com.example.jni.FLACStreamEncoder' to "com/example/jni/FLACStreamEncoder"
它仍然在LogCat中显示相同的错误。