在JNI_CreateJavaVM方法创建JVM时,我遇到了一个问题 “程序'[4616] VnptTokenCplusplus.exe:Native'退出了代码1(0x1)。”,有人可以为我解释一下吗?
#include <jni.h>
#pragma comment(lib,"jvm");
JNIEnv* Vnpt_JavaCreateVM();
void Vnpt_JavaInvokeClass(JNIEnv* env);
int main(){
JNIEnv* env = 0;
env = Vnpt_JavaCreateVM();
Vnpt_JavaInvokeClass(env);
getchar();
}
JNIEnv* Vnpt_JavaCreateVM() {
jint res;
JavaVM* jvm;
JNIEnv* env;
JavaVMInitArgs args;
JavaVMOption options[1];
args.version = JNI_VERSION_1_2; // JNI_VERSION_1_2 is interchangeable for this example
args.nOptions = 1;
options[0].optionString = "-Djava.class.path=.";
args.options = options;
args.ignoreUnrecognized = JNI_FALSE;
res = JNI_CreateJavaVM(&jvm, (void **)&env, &args);
if(res < 0)
{
}
return env;
}
void Vnpt_JavaInvokeClass(JNIEnv* env) {
jclass mainClass;
jmethodID mainMethod;
mainClass = env->FindClass( "com/vnpt/TestJDialog");
mainMethod = env->GetMethodID(mainClass, "tokenNotify", "()V");
env->CallVoidMethod(mainClass, mainMethod);
}
输出:
'VnptTokenCplusplus.exe': Loaded 'D:\Documents and Settings\tandaica0612\Desktop\VDC\BaoCao\Source\VnptToken\VnptTokenCplusplus\DebugX86\VnptTokenCplusplus.exe', Symbols loaded.
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\crypt32.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\msasn1.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\sechost.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'D:\Documents and Settings\tandaica0612\Desktop\VDC\BaoCao\Source\VnptToken\VnptTokenCplusplus\DebugX86\jvm.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\winmm.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\msvcr71.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file
'VnptTokenCplusplus.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file
The program '[4616] VnptTokenCplusplus.exe: Native' has exited with code 1 (0x1).
答案 0 :(得分:1)
我遇到了同样的问题并做了两件事来解决它:
1-将jvm.dll所在的位置(应该位于程序文件\ java \ jsdk_ * \ bin \ server中)添加到Windows机器上的PATH环境变量中
2-尝试更改“-Djava.class.path =”。指向实际目录或.jar文件(为我工作)