简体   繁体   English

通过JNI调用时Java抛出Null异常,但从Java程序调用时可以工作

[英]Java throws Null exception when calling via JNI but works when calling from Java program

I am using JNI to call Java methods from .jar library from external system. 我正在使用JNI从外部系统的.jar库中调用Java方法。 My problem is that everything works fine when I write simple Java program which uses the library, but when I am executing the same code via JNI the library throws Null exception when parsing Integer from String. 我的问题是,当我编写使用该库的简单Java程序时一切正常,但是当我通过JNI执行相同的代码时,从String解析Integer时,该库将引发Null异常。 I am sure that there is no problem in my JNI code, because I have a newer version of the library with the same interface which works fine via JNI. 我确信我的JNI代码没有问题,因为我有一个具有相同接口的较新版本的库,可以通过JNI正常工作。 But unfortunately I have to use the older version because of compatibility issues with external system. 但不幸的是,由于与外部系统的兼容性问题,我不得不使用旧版本。

I think that the problem is in the way how jvm.dll creates VM - I am probably missing some argument which I should pass to jvm.dll when creating VM. 我认为问题出在jvm.dll如何创建VM的方式上-我可能缺少一些参数,在创建VM时我应该将该参数传递给jvm.dll。 Does anyone know where the problem could be? 有人知道问题可能在哪里吗?

I can't post my code, but I can explain it on example: - library version 1 contatins class Router with constructor Router(int i) - I don't have the code for this class - library version 2 conatins same class with same constructor - when I write simple program 我无法发布我的代码,但可以在示例中进行解释:-库版本1包含构造函数Router(int i)的路由器类-我没有此类的代码-库版本2包含相同类的相同类构造函数-当我编写简单程序时

import java.lang.reflect.*;

public class Basic
{
    public static void main(String[] args)
    {
        Router = new Router(10); 
    }
}

it works with both libraries. 它适用于两个库。

When i run the same code with newer library 2 via JNI, it works too. 当我通过JNI在更新的库2中运行相同的代码时,它也起作用。 But when I run the code via JNI with library 1, it crashes due to following internal exception 但是当我通过带有库1的JNI运行代码时,由于以下内部异常,它崩溃了

    Error message: System.Exception: JAVA Exception: java.lang.NullPointerException
at com.coda.core.types.TypeNumber.parseNumber(TypeNumber.java:403)
at com.coda.core.types.TypeInteger.parse(TypeInteger.java:123)
at com.coda.core.types.TypeInteger.parse(TypeInteger.java:137)
at com.coda.core.Options.setOption(Options.java:138)
at com.coda.core.Options.set(Options.java:85)
at com.coda.core.configuration.ConfigurationLoader.getConfiguration(ConfigurationLoader.java:144)
at com.coda.xml.Configuration.init(Configuration.java:453)
at com.coda.xml.Configuration.init(Configuration.java:370)
at com.coda.xml.router.AppServer.<init>(AppServer.java:250)
at com.coda.xml.router.Router.<init>(Router.java:122)

I have solved the problem. 我已经解决了问题。 I had really mistake in parameters for JVM. 我在JVM参数方面确实犯了错误。 The older library requires another jar library what I didn't knew. 较旧的库需要另一个我不知道的jar库。 So I have added the library to class path and it works fine know. 因此,我已将该库添加到类路径中,并且很好地知道了。 Really stupid exception with nothing saying message turned me to look for a problem in wrong way. 真是愚蠢的例外,什么也没说,使我以错误的方式寻找问题。

Thanks everybody for comments 谢谢大家的评论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过JNI从C调用Java方法时,异常NOSUCHMETHODERROR - Exception NOSUCHMETHODERROR when calling Java method from C through JNI C ++代码可以正常工作,但从Java(JNI)调用时不起作用 - C++ code works fine but doesn't work when calling from Java (JNI) 从本机线程通过JNI回调时,Java线程泄漏 - Java thread leaks when calling back from native thread via JNI 从 Kotlin 调用用 Java 编写的方法时如何实现空安全,该方法引发异常? - How can I achieve Null-safety when calling a method written in Java from Kotlin, which throws an exception? 使用JNI从C调用Java代码时内存泄漏 - Memory leak when calling java code from C using JNI 在JBoss中通过XSLT调用Java函数会抛出变换器异常(在tomcat中工作) - Calling Java function via XSLT in JBoss throws transformer exception (works in tomcat) 从Web应用程序调用时,使用getResourceAsStream的Java InputStream对象为null,但在Eclipse中运行时可以使用 - Java InputStream object using getResourceAsStream is null when calling from web application but works when run in Eclipse 从JNI调用Java方法会导致程序崩溃 - Calling Java Methods from JNI results in program crash 使用JNI从cpp调用Java方法时发生异常 - Exception while calling java method from cpp using JNI 通过JNI从Java回调回本机应用程序 - Calling back into a native application from Java, via JNI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM