来自 java.lang.J9VMInternals 的 NullPointerException

发布于 2024-12-28 01:14:20 字数 2080 浏览 0 评论 0原文

我正在尝试运行 这个 Qt Jambi Hello World 示例 的稍微修改版本,但我遇到了NullPointerException 可追溯到我的第一行代码。唯一可能的方法似乎是 QApplication 为空,但它位于我的构建路径上,并且我的代码可以编译。

起初我想知道空指针是否是我缺少构造函数,但添加一个仍然会导致错误。现在我想知道是否是因为可能有一些 JNI(Java Native Access)在幕后运行以使 Qt Jambi 工作,或者尽管进行了编译(在 Eclipse 中),IDE 仍然无法正确执行文件 main 方法。

这是适用于 Windows 7 上的 Java 1.6

POSTSCRIPT: 您难道不知道使用 NetBeans 可以正常工作吗?感谢所有回答或评论的人。

代码:

import com.trolltech.qt.gui.*;

public class EcosDesk {
    public static void main(String args[]) {
        if(args == null) args = new String[0]; //suggested addition
        QApplication.initialize(args);

        QPushButton hello = new QPushButton("Hello World!");
        hello.show();

        QApplication.exec();
    }
}

堆栈跟踪:

Exception in thread "main" java.lang.NullPointerException
at java.lang.J9VMInternals$1.run(J9VMInternals.java:273)
at java.security.AccessController.doPrivileged(AccessController.java:202)
at java.lang.J9VMInternals.cloneThrowable(J9VMInternals.java:248)
at java.lang.J9VMInternals.copyThrowable(J9VMInternals.java:289)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:179)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:167)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:167)
at com.motion.ecos.EcosDesk.main(EcosDesk.java:7)

ECLIPSE 的 classpath.xml:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
    <classpathentry kind="lib" path="C:/Users/dp078008/Downloads/qtjambi-4.6.3-win32/qtjambi-4.6.3/qtjambi-4.6.3.jar"/>
    <classpathentry kind="lib" path="C:/Users/dp078008/Downloads/qtjambi-4.6.3-win32/qtjambi-4.6.3/qtjambi-win32-msvc2005-4.6.3.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

I'm trying to run a slightly modified version of this Qt Jambi Hello World example but I encounter a NullPointerException tracable to my very first line of code. The only way this would be possible would seem to be if QApplication is null, but it's on my build path, and my code compiles.

At first I wondered if the null pointer was my lack of a constructor, but adding one still results in the error. Now I'm wondering if it's because there is probably some JNI (Java Native Access) going on behind the scenes to make Qt Jambi work, or if despite compiling (in Eclipse), the IDE is still not executing the file main method correctly.

This is for Java 1.6 on Windows 7

POSTSCRIPT:
Woudn't you know it works fine using NetBeans. Thanks to everybody who answered or commented.

CODE:

import com.trolltech.qt.gui.*;

public class EcosDesk {
    public static void main(String args[]) {
        if(args == null) args = new String[0]; //suggested addition
        QApplication.initialize(args);

        QPushButton hello = new QPushButton("Hello World!");
        hello.show();

        QApplication.exec();
    }
}

STACK TRACE:

Exception in thread "main" java.lang.NullPointerException
at java.lang.J9VMInternals$1.run(J9VMInternals.java:273)
at java.security.AccessController.doPrivileged(AccessController.java:202)
at java.lang.J9VMInternals.cloneThrowable(J9VMInternals.java:248)
at java.lang.J9VMInternals.copyThrowable(J9VMInternals.java:289)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:179)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:167)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:167)
at com.motion.ecos.EcosDesk.main(EcosDesk.java:7)

ECLIPSE'S classpath.xml:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
    <classpathentry kind="lib" path="C:/Users/dp078008/Downloads/qtjambi-4.6.3-win32/qtjambi-4.6.3/qtjambi-4.6.3.jar"/>
    <classpathentry kind="lib" path="C:/Users/dp078008/Downloads/qtjambi-4.6.3-win32/qtjambi-4.6.3/qtjambi-win32-msvc2005-4.6.3.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-残月青衣踏尘吟 2025-01-04 01:14:20

可能 args 实际上是 null,因为您没有在 Eclipse 的运行配置中正确设置它

It could be that args is actually null because you didn't set it up correctly in the run Configurations in Eclipse

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文