1

Currently I'm trying to export my code to a Jar file that I can run from my desktop. The problem I am encountering is that when I am trying to run it, some of the buttons do not work, which is not the case when running the same program in NetBeans.

The program is a bot using sikulix libraries and the swingworker extension. Why this may be important, is because when trying the buttons found in the code, the ones with significant amounts of code using swingworker happen to be the ones not working.

My method of exporting is based on this guide: http://www.oracle.com/technetwork/articles/javase/index-139904.html

The whole exporting process, works as intended (or at least as the tutorial shows) - yet some functions do not work in the exported version. So, my question to You is: What may be causing the program to just partially work?

After running the program with CMD and pressing one of the buttons, the following error occured:

Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
        at coreClass.actionPerformed(coreClass.java:64)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$500(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.NullPointerException
        at org.sikuli.script.Image.<init>(Image.java:759)
        at org.sikuli.script.Image.create(Image.java:599)
        at org.sikuli.script.Pattern.<init>(Pattern.java:82)
        at B10.<clinit>(B10.java:22)
        ... 37 more
Gregdl
  • 11
  • 4
  • did you mean Java instead of JavaScript? – Birchlabs Sep 13 '17 at 14:09
  • What do you mean when you say that the button "does not work"? What do they do instead of working? Is there any output, error, or UI feedback? – Birchlabs Sep 13 '17 at 14:10
  • @Birchlabs Hey, by javascript i mean a script written in java, I do not really see any confusing here? When I say that the buttons do not work, I mean that when pressed, there is literally no action taking place - which is not the case when the same script is being run in netbeans. – Gregdl Sep 13 '17 at 14:17
  • Typically there is two kind of problems, missing code and missing files. You need to explain better. – Thorbjørn Ravn Andersen Sep 13 '17 at 14:17
  • I will explain better, if You could help me out by asking what part is unclear, would attaching the code help maybe? – Gregdl Sep 13 '17 at 14:19
  • it's possible that the program is outputting an error, and you are not seeing it. are you launching your jar from the command-line (i.e. using `java -jar mycooljar`)? you would (usually) see exceptions output into your terminal. do you see any such error output when you click your button? – Birchlabs Sep 13 '17 at 14:24
  • @Birchlabs Until now I have never run a jar from cmd, but now that i tried it, it showed quite some issues. The message when pressing the not working button was following (adding it in problem desc, just wait a second)! :) – Gregdl Sep 13 '17 at 14:30
  • Okay, looks like you tried to perform some action on a _null_ image. My gut feeling is that you attempted to construct an image from some file, but the file was not found. This is a common problem that occurs when you launch your application in a different manner (working directory, classpath or execution context changes). You should make your application tell you as early as possible when it fails to find a file. – Birchlabs Sep 13 '17 at 14:39
  • @Birchlabs That is a good idea, but I do not really udnerstand why this exact same program works perfectly when launched in NetBeans, and not when exported? It feels like the problem lays somewhere with the exporting, what is your opinion? – Gregdl Sep 13 '17 at 14:41
  • you are assuming that it's the same program, and you are assuming that it's executed in the same way. you should look inside the jar to check whether it contains everything that you think it contains, and whether those items are in the location you think they are. to open the jar: rename the .jar to a .zip (they're the same thing), and extract that zip. – Birchlabs Sep 13 '17 at 15:24
  • @Birchlabs hmm, could You maybe elaborate on the "assuming it's the same program" part? From my understanding if I write a code, and then export it, then it is still the same code? Also, when extracting the file, I find everything that I think is supposed to be there. All classes, resources, libraries etc. This is such a annoying problem... :( – Gregdl Sep 13 '17 at 15:52
  • "Export" is not magic. Bundling is complicated; one of the hardest problems in software engineering. How does NetBeans' build system know what you want to put in your jar, and what directory you want to put it in? There's plenty of ways for this to go wrong. – Birchlabs Sep 13 '17 at 15:54
  • @Birchlabs You are correct, and that is why I posted the way I did it in the problem description. Just so people willing to help me know what I did, and possibly what I should do differently :/ – Gregdl Sep 13 '17 at 15:56
  • Did you try my suggestion of "make your application tell you as early as possible when it fails to find a file"? There's no point doing this blind; it's almost definitely failing to find some file. Find out which one. Find out where it _expected_ the file to be. Then investigate why it's not there. – Birchlabs Sep 13 '17 at 15:59
  • @Birchlabs How would You approach this? My problem is that I do not understand the error it is spitting out in CMD, and by "missing a file" do You mean the resources, libraries, or what specifically? – Gregdl Sep 13 '17 at 16:03
  • I don't have the source symbols, so I don't know what field Java is attempting to access when it encounters a NullPointerException at `org.sikuli.script.Image.java:759`. only you can investigate this; attach a debugger and see what variable is null. my intuition is that it's some resource that the Image requires in order to exist, so it's likely to be a missing file. if you know which Image is affected, you can probably guess which files it depends on (they are likely graphical assets that you are responsible for). – Birchlabs Sep 13 '17 at 16:12
  • if you've no idea how to debug this at application-level, then debug it at kernel-level. on macOS you can use [opensnoop](http://dtrace.org/blogs/brendan/2011/10/10/top-10-dtrace-scripts-for-mac-os-x/), on Windows you can use [SysInternals Process Monitor (ProcMon)](https://learn.microsoft.com/en-us/sysinternals/downloads/procmon). Either of these utilities will tell you in real-time which files your program attempts to open, and you can check the return code (-1 in opensnoop) to detect situations where the program fails to find a file, and where it tried looking. – Birchlabs Sep 13 '17 at 16:15

0 Answers0