0

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>
Dexygen
  • 12,287
  • 13
  • 80
  • 147
  • Can you try to run this on the command line? – Viruzzo Jan 19 '12 at 16:42
  • I think adding the run configuration to Eclipse has the same essential effect as running from the command line – Dexygen Jan 19 '12 at 17:15
  • Can you be clear which version of Qt Jambi you are using ? I guess 4.6.3 msvc2005 for windows 32 bit. Did you download this sourceforge? – Darryl Miles Jan 19 '12 at 21:25
  • Maybe related FWIW: http://stackoverflow.com/questions/2691894/qtjambi-qapplication-initialize-outside-of-main-method – Darryl Miles Jan 19 '12 at 21:31
  • Have added if(args == null) args = new String[0]; to no avail. Could it be not setting an environment variable? The directory that contains QtCore.dll and all the other dll's *is* on my path (for me, for now: C:\Users\dp078008\Documents\qtjambi-4.7.1\bin) – Dexygen Jan 19 '12 at 21:47
  • I tried 4.6.3 for Windows 32 bit first, then I switched to version 4.7.1 – Dexygen Jan 19 '12 at 21:56
  • Is there any specific reason you are using IBM JRE? Will this exception happen if you switch to Oracle JRE? – ᄂ ᄀ Jan 19 '12 at 22:04
  • What is the IBM JRE -version output (so maybe I can make a note to test) ? Are you sure its the 32bit JRE setup in the launch configuration ? (I think maybe you get a different kind of error if there was a mismatch). – Darryl Miles Jan 19 '12 at 22:08
  • Does it crash if you specify some random argumemt value in Eclipse launch configuration ? So it is passed one or more String values ? – Darryl Miles Jan 19 '12 at 22:26
  • i heard of that, a colleage said it's an IBM JRE bug – CKey Sep 15 '21 at 08:52

1 Answers1

2

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

Adel Boutros
  • 10,205
  • 7
  • 55
  • 89
  • Good idea but unfortunately same result; I set "arg0" as a command line argument in the run config, then modified the code to first print it to console; that worked, but then an error got thrown pointing to the very next line: "QApplication.initialize(args);" – Dexygen Jan 19 '12 at 16:55
  • @GeorgeJempty are you sure you can write jsut 1 parameter? doesn't QApplication require 2 parameters? Check this link: [QApplication Constructor](http://developer.qt.nokia.com/doc/qt-4.8/qapplication.html#QApplication) – Adel Boutros Jan 19 '12 at 17:00
  • I don't think that is the case for the Java API, all the examples I've seen, including other questions right here on SO and the qt-jambi javadoc at http://doc.trolltech.com/qtjambi-4.5.0_01/index.html?com/trolltech/qt/gui/QApplication.html, it seems QApplication.initialize is merely a mechanism for passing the command line arguments through – Dexygen Jan 19 '12 at 17:13
  • @GeorgeJempty Why not debug it and step into it. Then identify the line causing the error. It would be helpful – Adel Boutros Jan 19 '12 at 17:15
  • Yes try with if(args == null) args = new String[0]; QApplication.initialize(args); – Darryl Miles Jan 19 '12 at 21:27