Replies: 7 comments 8 replies
-
Hi, that ExceptionInInitializerError is an error not an exception, and probably has something to do with native libraries. Can you show us the stack trace? |
Beta Was this translation helpful? Give feedback.
-
I believe this user is attempting to run pi4j on their development machine, not on a Pi. Am I correct you are executing your code on a machine that is not an ARM based Pi ? |
Beta Was this translation helpful? Give feedback.
-
I will ask @eitch or @FDelporte to comment if they see a different answer. Pi4j-V2 targets only the Raspberry Pi family and no other architectures and IO structure. So I do not believe we will create any stubs programs to support your test method. Likely some change in java code, build process or native code resulted in the failure surfacing differently in 2.6 |
Beta Was this translation helpful? Give feedback.
-
@Ir3nicuz can you supply the stack trace? At the moment i don't know what component is failing in your case, and can thus not offer a fix. What i can say, is that we usually implement the pi4j in its own component using an interface, then one can simply detect that one is running on the desktop and use a different concrete class which does not use pi4j. Another concrete class can then be instantiated when running on the Raspberry Pi, which then communicates with the pi4j library. |
Beta Was this translation helpful? Give feedback.
-
I found this little bit hackish workaround but good enough for now (at least for windows where no "BoardModel" exists):
Putting this before the context creation in my initialise method solved the problem. |
Beta Was this translation helpful? Give feedback.
-
In my opinion, it would be best, that you load the mock context when on a non-Raspberry Pi platform. See an example here: https://github.com/Pi4J/pi4j-template-javafx/blob/main/src/main/java/com/pi4j/mvc/util/Pi4JContext.java |
Beta Was this translation helpful? Give feedback.
-
I am glad you found a solution. |
Beta Was this translation helpful? Give feedback.
-
Today I updated my program from pi4j 2.3.0 to 2.6.0 and i now i have the issue that i cannot catch content creation errors properly.
My IDE runs on windows, so I expect that before deploying to the Raspberry the pi4j content cannot be created.
I faced this by adding "throws Exception" to the initializer and it was good enough to test and debug the program without the hardware part before deploying and test the hardware part after deploying.
But with 2.6.0 the content creation or the output creation no longer throws a catchable exception. Instead i get a non-catchable "java.lang.ExceptionInInitializerError".
Is there another way to check the content on validity and relay that to an exception?
public final void initialize() throws Exception { Pi4jContext = Pi4J.newAutoContext(); DigitalOutput output = Pi4jContext.create(DigitalOutput.newConfigBuilder(Pi4jContext) .provider("pigpio-digital-output") .address(gpioNumber) .initial(initState) .shutdown(shutdownState)); }
Beta Was this translation helpful? Give feedback.
All reactions