我正在尝试使用DefineClass,它是Java Native Interface 的一部分。该方法采用 a const jbyte*
,const signed char*
我正在尝试从 Qt 资源中解析它。但是一定有什么问题,因为ExceptionDescribe()
打印java.lang.ClassFormatError: Truncated class file。
QFile qfile(":/SomeClass.class");
qfile.open(QFile::ReadOnly)
QByteArray qbytes = qfile.readAll();
char *test = qbytes.data();
jbyte *buf = reinterpret_cast<jbyte*>(test);
jclass processorCls = env->DefineClass("example/SomeClass", nullptr, buf, sizeof(buf));
if (env->ExceptionCheck())
{
env->ExceptionDescribe();
env->ExceptionClear();
}
我可以验证资源是否有效,因为我能够qfile
使用此处找到的方法打印 的内容。
void read(QString fName)
{
QFile file(fName);
if (!file.open(QFile::ReadOnly | QFile::Text))
{
std::cout << "Could not open the file for reading" << std::endl;
return;
}
QTextStream in(&file);
QString text = in.readAll();
std::cout << text << std::endl;
file.close();
}
的sizeof(buf)
返回指针的大小,而不是缓冲区的大小。请qbytes.size()
改用 。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句