2011-11-03 2 views
0

J'ai un problème lors de la création JVM à la méthode JNI_CreateJavaVM, application juste "Le programme" [4616] VnptTokenCplusplus.exe: Native 'est sorti avec le code 1 (0x1). ", Quelqu'un peut-il expliquer cela pour moi?JNI_CreateJavaVM code de sortie -1?

#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); 
} 

Et sortie:

'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

Je vous suggère de mettre quelque chose d'utile dans le bloc 'if (res <0)' avant d'aller plus loin. Ignorer les cas d'échec n'est jamais une bonne idée: comme ici, cela vous donne quelque chose de plus difficile à déboguer. – EJP

Répondre

1

Je faisais la même question et a fait deux choses pour le résoudre:

1- Ajouter le lieu où réside jvm.dll (devrait être dans le program files \ java \ jsdk_ * \ bin \ server) à la variable d'environnement PATH sur votre machine windows

2- Essayez de changer le "-Djava.class.path =." pour pointer vers un répertoire réel ou un fichier .jar (travaillé pour moi)

Questions connexes