问题
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>
回答1:
It could be that args
is actually null
because you didn't set it up correctly in the run Configurations in Eclipse
来源:https://stackoverflow.com/questions/8929559/nullpointerexception-from-java-lang-j9vminternals