Hi. I am simply having issue starting the Arduino service in mrl through Intellij on my  x64 intel cpu desktop PC.

My steps that led to the issue are as follows: 

  • I cloned  MRL through intellij using the url https://github.com/MyRobotLab/myrobotlab.git 
  • I ran the SwingGui service's main method,
  • I right clicked on the Arduino service in the SwingGui's service list and click start to start the Arduino service.
  • I get the error "createAndStart(arduino, org.myrobotlab.service.Arduino) java.lang.NullPointerException" at the bottom of the SwingGui window and the Arduino service doesnt start. 

I have already switched to the  Java 1.8  JDK in both my environment variables (path and JAVA_HOME) , and I have set the MRL nixie project in the IDE to use the 1.8 JDK. I have checked that running "java -version" in cmd returns 1.8  and that the IDE log shows that I am using 1.8 when I run any main method in the project, so it shouldnt be an issue of java version.  Manticore runs the Arduino service fine using the Jar.  However, trying to run the Arduino service in nixie in my IDE (either by the method above, or directly via Runtime.start("myarduino", "Arduino"); )  does not work and gives me a null pointer exception which is traced back to a failure of the Arduino service to create a Registration, at the point where the service is converted toJson.  I will share my code with you @Kwatters or @Grog, in case you want to inspect  the MRL package I have for cause of the issue. I tried pushing my new branch but git said remote permission was denied to my username.  

Ray.Edgley

4 years 5 months ago

You need it to be running on the Raspberry Pi for this service to work.

Also check your version of Java

Null pointers can come from anywhere. You need to share with us the full exception not the the type of exception. There is usually information about what line number caused the exception... That's very important.

That being said . You should be doing this testing as a unit test.. not just randomly launching some services main method.

Here is an old video that I did. Hopefully it helps.

https://youtu.be/XvxO07uoXLk

GroG

4 years 5 months ago

Hi Alex.
Testing locally on my system using SwingGui's main ... I get worky - I'm a little ahead of the latest Nixie, but I don't see any fixes locally that would be relevant.

You don't need permissions to do a pr
https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork - this is how most of my prs to other projects are done (I've done several against Apache Ivy)

The quickest way I suspect to get to the root of this is to see a noWorky

Hi Grog! So, thank for testing the arduino service via the jar. It appears im only having issues with the ide clone. The jar version that I downloaded  an hour ago   is 1.1.1.95 , however, the IDE clone, which i cloned an hour ago into a new directory,  is 1.1.1.86. I used this url to clone today  https://github.com/MyRobotLab/myrobotlab.git     Ive had no problem whatsoever getting the jar to run the arduino service (in both the web gui and swing gui) but still cant get the cloned ide version to create the arduino service either by running the swing gui service's main and clicking start on the arduino service in that swing gui list, or by adding "Runtime.start("arduino", "Arduino")"  to the swinggui. Ive also tried opening the arduino service by starting the swinggui service, then clicking on the web gui service and, then trying to start the Arduino service. In any case, any attempt to run the Arduino service via the IDE is not working. I want to post my error log so you can see exactly what is happening, but im not sure if it will format correctly in these comments. Perhaps its just 1.1.1.86 that is the issue. Let me know what you think. 

 
So, what i did was simply add the line "Runtime.start("arduino", "Arduino");"  to the SwingGui service's main and then ran that.  No other code was added/edited/removed from the newly cloned project.  
 
 
 
 
runtime@r1 /]#
15:19:33.135 [main] INFO  c.myrobotlab.service.SwingGui - tabs size 0
15:19:33.135 [main] INFO  c.myrobotlab.framework.Service - subscribe [runtime/released ---> gui/removeTab]
15:19:33.136 [main] INFO  c.myrobotlab.framework.Service - subscribe [runtime/registered ---> gui/onRegistered]
15:19:33.138 [main] INFO  c.myrobotlab.framework.MethodCache - caching Welcome's 58 methods and 0 declared methods
15:19:33.138 [main] INFO  c.myrobotlab.framework.MethodCache - cached Welcome 58 methods with 58 ordinal signatures in 0 ms
15:19:33.304 [main] INFO  c.myrobotlab.service.SwingGui - buildTabPanels service count 3
15:19:33.314 [AWT-EventQueue-0] INFO  c.myrobotlab.framework.MethodCache - caching SwingGuiGui's 67 methods and 11 declared methods
15:19:33.317 [AWT-EventQueue-0] INFO  c.myrobotlab.framework.MethodCache - cached SwingGuiGui 67 methods with 67 ordinal signatures in 3 ms
15:19:33.433 [main] INFO  class org.myrobotlab.service.Runtime - Runtime.createService arduino
15:19:33.441 [main] INFO  c.myrobotlab.framework.Service - creating remote proxy service for id r1
15:19:33.451 [main] INFO  c.myrobotlab.framework.MethodCache - caching Arduino's 352 methods and 137 declared methods
15:19:33.455 [main] INFO  c.myrobotlab.framework.MethodCache - cached Arduino 352 methods with 319 ordinal signatures in 14 ms
15:19:33.456 [main] INFO  c.myrobotlab.framework.Service - found override resource dir src\main\resources\resource\Arduino
15:19:33.456 [main] INFO  c.myrobotlab.service.data.Locale - src\main\resources\resource\Arduino\localization\en.properties does not exist
15:19:33.456 [main] INFO  c.myrobotlab.framework.Service - found override resource dir src\main\resources\resource\Arduino
15:19:33.456 [main] INFO  c.myrobotlab.service.data.Locale - src\main\resources\resource\Arduino\localization\en.properties does not exist
15:19:33.457 [main] INFO  c.myrobotlab.framework.Service - found override resource dir src\main\resources\resource\Arduino
15:19:33.457 [main] INFO  c.myrobotlab.framework.Registration - creating registration for arduino@r1 - org.myrobotlab.service.Arduino
15:19:33.466 [main] ERROR class org.myrobotlab.service.Runtime - createService failed for arduino@null of type org.myrobotlab.service.Arduino
java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_251]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_251]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_251]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_251]
at org.myrobotlab.framework.Instantiator.getThrowableNewInstance(Instantiator.java:54) ~[classes/:na]
at org.myrobotlab.service.Runtime.createService(Runtime.java:435) [classes/:na]
at org.myrobotlab.service.Runtime.create(Runtime.java:297) [classes/:na]
at org.myrobotlab.service.Runtime.createAndStart(Runtime.java:326) [classes/:na]
at org.myrobotlab.service.Runtime.start(Runtime.java:1793) [classes/:na]
at org.myrobotlab.service.SwingGui.main(SwingGui.java:932) [classes/:na]
Caused by: java.lang.NoClassDefFoundError: Lcom/pi4j/io/gpio/GpioPinDigitalMultipurpose;
at java.lang.Class.getDeclaredFields0(Native Method) ~[na:1.8.0_251]
at java.lang.Class.privateGetDeclaredFields(Class.java:2583) ~[na:1.8.0_251]
at java.lang.Class.getDeclaredFields(Class.java:1916) ~[na:1.8.0_251]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:152) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102) ~[gson-2.8.5.jar:na]
at com.google.gson.Gson.getAdapter(Gson.java:458) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.MapTypeAdapterFactory.create(MapTypeAdapterFactory.java:126) ~[gson-2.8.5.jar:na]
at com.google.gson.Gson.getAdapter(Gson.java:458) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102) ~[gson-2.8.5.jar:na]
at com.google.gson.Gson.getAdapter(Gson.java:458) ~[gson-2.8.5.jar:na]
at com.google.gson.Gson.toJson(Gson.java:696) ~[gson-2.8.5.jar:na]
at com.google.gson.Gson.toJson(Gson.java:683) ~[gson-2.8.5.jar:na]
at com.google.gson.Gson.toJson(Gson.java:638) ~[gson-2.8.5.jar:na]
at com.google.gson.Gson.toJson(Gson.java:618) ~[gson-2.8.5.jar:na]
at org.myrobotlab.codec.CodecUtils.toJson(CodecUtils.java:255) ~[classes/:na]
at org.myrobotlab.framework.Registration.<init>(Registration.java:55) ~[classes/:na]
at org.myrobotlab.framework.Service.<init>(Service.java:1090) ~[classes/:na]
at org.myrobotlab.service.abstracts.AbstractMicrocontroller.<init>(AbstractMicrocontroller.java:82) ~[classes/:na]
at org.myrobotlab.service.Arduino.<init>(Arduino.java:220) ~[classes/:na]
... 10 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.pi4j.io.gpio.GpioPinDigitalMultipurpose
at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_251]
at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_251]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[na:1.8.0_251]
at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_251]
... 31 common frames omitted
15:19:33.467 [main] ERROR c.myrobotlab.framework.Service - runtime error createAndStart(arduino, Arduino) java.lang.NullPointerException
15:19:33.467 [main] ERROR class org.myrobotlab.service.Runtime - createAndStart(arduino, Arduino) java.lang.NullPointerException
java.lang.NullPointerException: null
at org.myrobotlab.service.Runtime.createAndStart(Runtime.java:327) [classes/:na]
at org.myrobotlab.service.Runtime.start(Runtime.java:1793) [classes/:na]
at org.myrobotlab.service.SwingGui.main(SwingGui.java:932) [classes/:na]
15:19:33.602 [AWT-EventQueue-0] INFO  c.myrobotlab.framework.Service - subscribe [gui@r1/publishStatus ---> gui/onStatus]
15:19:33.602 [AWT-EventQueue-0] INFO  c.myrobotlab.framework.Service - subscribe [gui@r1/publishState ---> gui/onState]
15:19:33.623 [AWT-EventQueue-0] INFO  c.myrobotlab.framework.MethodCache - caching RuntimeGui's 79 methods and 25 declared methods
15:19:33.624 [AWT-EventQueue-0] INFO  c.myrobotlab.framework.MethodCache - cached RuntimeGui 79 methods with 78 ordinal signatures in 1 ms
15:19:33.661 [AWT-EventQueue-0] INFO  c.myrobotlab.framework.Service - subscribe [runtime@r1/publishStatus ---> gui/onStatus]
15:19:33.661 [AWT-EventQueue-0] INFO  c.myrobotlab.framework.Service - subscribe [runtime@r1/publishState ---> gui/onState]
15:19:33.775 [AWT-EventQueue-0] INFO  c.myrobotlab.framework.MethodCache - caching SecurityGui's 60 methods and 4 declared methods
15:19:33.776 [AWT-EventQueue-0] INFO  c.myrobotlab.framework.MethodCache - cached SecurityGui 60 methods with 60 ordinal signatures in 1 ms
15:19:33.778 [AWT-EventQueue-0] INFO  c.myrobotlab.framework.Service - subscribe [security@r1/publishStatus ---> gui/onStatus]
15:19:33.778 [AWT-EventQueue-0] INFO  c.myrobotlab.framework.Service - subscribe [security@r1/publishState ---> gui/onState]
 

hmmm ...
if their not defined they should evaluete to "nothing" which should be fine ..

Apache Maven (the group that defined the pom) handles this without problem...
Is it just a linting problem in Intellij - or is it not building because of it ?

There has got to be a way to set env variables in Intellij

The reason they are there is because our Ci/Cd (Jenkins) passes the vars on each build.

The ones you pointed out in the pom.xml file, if that is really an issue...

I'm not too familiar with intellj - otherwise I would be able to help more,

but I'm pretty sure "for whatever reason, your IDE is not correctly processing the pom.xml"
(usually this is maven under the hood)

Ahoy. So I got the arduino service running in the ide, but now im running into another issue that ive slowly tracked down. The Arduino service uses the Serial class , which  implements the JSSC library classes, to make a connection to the serial ports. Unforturnately, although maven has dowloaded the jssc dependency into my .m2 repository, the JSSC directory that the Serial class imports from is not found in my project directory.  Im not sure why this is the case, but my only guess was that perhaps there was supposed to be an additional step for maven to decompile the JSSC jar in the .m2 directory into the MRL project directory. Let me know what you think might be the issue here when you come back online. Thanks. 

all of this stuff magically just works fine in eclipse and with command line maven.  I suspect all of your issues are related to how the project was imported into intellij.  have you tried eclipse?  

There's not magic de-compiling..   the ".m2" directory is where maven caches the jar files that it downloads.  intellij will use the same one.