访问冲突读取位置0x

访问冲突读取位置0x

本文介绍了0xC0000005:访问冲突读取位置0x0000000000000000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JNI在c ++程序中使用jar文件.

I'm trying to use a jar file in c++ program using JNI.

我这样做了:

// TestJavaToCpp.cpp : Defines the entry point for the console application.
//

#include <jni.h>
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <iostream>

using namespace std;


int main()
{
    JavaVM *jvm;
    JNIEnv *env;
    JavaVMInitArgs vm_args;
    JavaVMOption options;
    options.optionString = "-Djava.class.path=HelloWorld.jar";
    vm_args.version = JNI_VERSION_1_6;
    vm_args.nOptions = 1;
    vm_args.options = &options;
    vm_args.ignoreUnrecognized = 0;
    int ret = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
    if (ret == 0) {
        jclass cls = env->FindClass("HelloWorld");
        if (cls != 0) {
            jmethodID meth = env->GetStaticMethodID(cls, "Hello", "([Ljava/lang/String;)V");
            jarray args = env->NewObjectArray(0, env->FindClass("java/lang/String"), 0);
            env->CallStaticVoidMethod(cls, meth, args);
        }
    }
    return ret;
}

HelloWorld.jar与exe文件位于同一文件夹中时.但是,我不断收到错误消息

When HelloWorld.jar is in the same folder with the exe file.However, i keep getting the error

尝试创建JVM时.

现在代码看起来像这样:

EDIT 1:Now code looks like this:

// TestJava.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <jni.h>
#include <Windows.h>
#include <stdio.h>
#include <iostream>

using namespace std;

#define CLEAR(x) memset(&x, 0, sizeof(x))

int main()
{
    JavaVM *jvm(0);
    JNIEnv *env(0);
    JavaVMInitArgs vm_args;
    CLEAR(vm_args);
    JavaVMOption options;
    CLEAR(options);

    options.optionString = "-Djava.class.path=HelloWorld.jar";
    options.extraInfo = 0;
    vm_args.version = JNI_VERSION_1_8;
    vm_args.nOptions = 1;
    vm_args.options = &options;
    vm_args.ignoreUnrecognized = 0;
    int ret = JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args);

    return 0;
}

我只留下了实际创建虚拟机的代码.当它起作用时,我继续,

I left only the code that actually creates the vm. When it'll work, I'll go on,

现在我已经注意到以前出现的错误,但是我没有注意它们:

And now I have noticed to error that showed up before but i didn't pay attention to them:

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ ntdll.dll'.不能查找或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannotfind or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ kernel32.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ KernelBase.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'.Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ apphelp.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\apphelp.dll'. Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ vcruntime140d.dll'.找不到或打开PDB文件.'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ ucrtbased.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\vcruntime140d.dll'. Cannot find or open the PDBfile.'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Program Files(x86)\ Java \ jdk1.8.0_91 \ jre \ bin \ client \ jvm.dll'.找不到或打开PDB文件.'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ advapi32.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Program Files(x86)\Java\jdk1.8.0_91\jre\bin\client\jvm.dll'. Cannot find or openthe PDB file.'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ user32.dll'.找不到或打开PDB文件.'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ msvcrt.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'.Cannot find or open the PDB file.'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ gdi32.dll'.不能查找或打开PDB文件.'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ wsock32.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Cannotfind or open the PDB file.'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\wsock32.dll'. Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ winmm.dll'.不能查找或打开PDB文件.'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ sechost.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmm.dll'. Cannotfind or open the PDB file.'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ psapi.dll'.不能查找或打开PDB文件.'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ version.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Windows\SysWOW64\psapi.dll'. Cannotfind or open the PDB file.'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\version.dll'. Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ winmmbase.dll'.找不到或打开PDB文件.'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ msvcr100.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmmbase.dll'.Cannot find or open the PDB file.'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\msvcr100.dll'. Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ rpcrt4.dll'.找不到或打开PDB文件.'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ cfgmgr32.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'.Cannot find or open the PDB file.'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\cfgmgr32.dll'. Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ ws2_32.dll'.找不到或打开PDB文件.'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ sspicli.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ws2_32.dll'.Cannot find or open the PDB file.'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ cryptbase.dll'.找不到或打开PDB文件.'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ bcryptprimitives.dll'.找不到或打开PDB文件.'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ imm32.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'.Cannot find or open the PDB file.'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open thePDB file.'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\imm32.dll'. Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Program Files(x86)\ Java \ jdk1.8.0_91 \ jre \ bin \ verify.dll'.找不到或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Program Files(x86)\Java\jdk1.8.0_91\jre\bin\verify.dll'. Cannot find or open thePDB file.

'TestJava.exe'(Win32):已加载'C:\ Program Files(x86)\ Java \ jdk1.8.0_91 \ jre \ bin \ java.dll'.找不到或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Program Files(x86)\Java\jdk1.8.0_91\jre\bin\java.dll'. Cannot find or open the PDBfile.

'TestJava.exe'(Win32):已加载'C:\ Program Files(x86)\ Java \ jdk1.8.0_91 \ jre \ bin \ zip.dll'.找不到或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Program Files(x86)\Java\jdk1.8.0_91\jre\bin\zip.dll'. Cannot find or open the PDBfile.

在TestJava.exe中的0x025A0202处引发的异常:0xC0000005:访问冲突读取位置0x00000000.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ shell32.dll'.找不到或打开PDB文件.'TestJava.exe'(Win32):已加载

'TestJava.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'.Cannot find or open the PDB file.'TestJava.exe' (Win32): Loaded

'C:\ Windows \ SysWOW64 \ windows.storage.dll'.找不到或打开PDB文件.

'C:\Windows\SysWOW64\windows.storage.dll'. Cannot find or open the PDBfile.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ combase.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\combase.dll'. Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ shlwapi.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'.Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ kernel.appcore.dll'.找不到或打开PDB文件.

'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\kernel.appcore.dll'. Cannot find or open the PDBfile.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ SHCore.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Windows\SysWOW64\SHCore.dll'.Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ powrprof.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded'C:\Windows\SysWOW64\powrprof.dll'. Cannot find or open the PDB file.

'TestJava.exe'(Win32):已加载'C:\ Windows \ SysWOW64 \ profapi.dll'.无法找到或打开PDB文件.

'TestJava.exe' (Win32): Loaded 'C:\Windows\SysWOW64\profapi.dll'.Cannot find or open the PDB file.

线程0x2760已经退出代码0(0x0).

The thread 0x2760 has exited withcode 0 (0x0).

线程0x494c已退出,代码为0(0x0).

The thread 0x494c has exited with code 0 (0x0).

线程0x3368已退出,代码为0(0x0).

Thethread 0x3368 has exited with code 0 (0x0).

线程0x2e48具有退出,代码为0(0x0).

The thread 0x2e48 hasexited with code 0 (0x0).

线程0x3d5c已退出,代码为0(0x0).

The thread 0x3d5c has exited with code 0(0x0).

线程0x3b2c已退出,代码为0(0x0).

The thread 0x3b2c has exited with code 0 (0x0).

线程0x4490已退出,代码为0(0x0).

The thread0x4490 has exited with code 0 (0x0).

线程0x3bb4已退出代码0(0x0).线程0x4d18已退出,代码为0(0x0).

The thread 0x3bb4 has exited withcode 0 (0x0). The thread 0x4d18 has exited with code 0 (0x0).

线程0x2cac已退出,代码为0(0x0).

Thethread 0x2cac has exited with code 0 (0x0).

线程0x4ec8具有退出,代码为0(0x0).

The thread 0x4ec8 hasexited with code 0 (0x0).

程序[[18476] TestJava.exe"具有退出,代码为0(0x0).

The program '[18476] TestJava.exe' hasexited with code 0 (0x0).

看大胆的句子.这是引发异常的地方...

Look on the bold sentence. This is where the exception is being thrown...

推荐答案

您需要设置options.extraInfo = 0;

我会尽一切努力做到这一点.防御性编程要求将所有内容初始化.

I would do all of this for good measure. Defensive programming demands that everything is initialized.

#define CLEAR(x) memset(&x, 0, sizeof(x))
JavaVM *jvm(0);
JNIEnv *env(0);
JavaVMInitArgs vm_args;
CLEAR(vm_args);
JavaVMOption options;
CLEAR(options);

注意:

typedef struct JavaVMOption {
    char *optionString;
    void *extraInfo;
} JavaVMOption;

所有这些都不是问题所在.解决方案在注释中-JVM抛出访问冲突异常.它们已被捕获并处理,但是在Visual Studio导致您相信存在问题之前就没有.

None of this turned out to be the problem. The solution is in the comments -- the JVM is throwing access violation exceptions. They are caught and handled, but not before Visual Studio leads you to believe there is a problem.

这篇关于0xC0000005:访问冲突读取位置0x0000000000000000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 06:47