java.lang.UnsatisfiedLinkError: jssc.SerialNativeInterface.getSerialPortNames() - java

I'm doing a processing based project with eclipse and Procliping. When I'm testing the project with "Run" command inside the IDE, everything works fine. But if I export it into a runable-jar, when I run the jar it'll give this error on the line String[] li=Serial.list();. Any idea what's going wrong?
Java source attachment is "processing-2.2.1/modes/java/libraries/serial/src"
And here is a sample code:
package abcd;
import processing.core.PApplet;
import processing.serial.Serial;
public class TestUI extends PApplet {
Serial port;
public void setup(){
System.out.println(Serial.list());
}
public void draw(){
}
public static void main(String _args[]) {
PApplet.main(new String[] { abcd.TestUI.class.getName() });
}
}

My approach of solving it:
Download the latest version of java-simple-serial-connector(Which is the base library used for Processing's serial library), replace jssc.jar in the lib folder, and the error will be gone, and my application runs smoothly.
However the base library is 4 times bigger than the modified version used in Processing, so there may be some unnecessary features involved.
Seems like in their latest alpha version, Processing solved the same problem for exporting apps(at least in windows) by adding more look-up paths, while keeping their Serial library intact. I'm not familiar with their development environment, so I didn't look further into it. There may be a simpler solution.

Related

Why the exported to desktop (.exe) processing app with java classes can not run properly? My another project was exported without problems

I try to export my processing app as the "ready to use" application with exe launch file for desktop.
My code is pretty simple. Proccessing code:
//import io.itch.mgdsstudio.airfight.connecteddevices.*;
private io.itch.mgdsstudio.airfight.connecteddevices.Controller controller;
void setup(){
size(600,800, JAVA2D);
background(0);
//I think the next code line can not be launched after export. Background stays black
controller = new io.itch.mgdsstudio.airfight.connecteddevices.Controller(this);
}
void draw(){
controller.render();
}
and the java-class:
package io.itch.mgdsstudio.airfight.connecteddevices;
import processing.core.PApplet;
public class Controller {
private PApplet engine;
public Controller(PApplet engine) {
this.engine = engine;
}
public void render(){
engine.background(255,0,0);
}
}
The application runs perfect from processing ide - the screen is red. But after export it can not run properly. The screen is black. I tested processing 3 and 4. In january I exported an another application succesfully. But now I can not launch exported file. I think the trouble is in versions of the java source files.
I tried to change code so:
import io.itch.mgdsstudio.airfight.connecteddevices.Controller;
private Controller controller;
void setup(){
size(600,800, JAVA2D);
background(0);
controller = new Controller(this);
}
void draw(){
controller.render();
}
I receive the message in the console:
No library found for io.itch.mgdsstudio.airfight.connecteddevices
but it runs in the ide. But after export it can not run properly again. Maybe i need another package names?
There seems to be an issue/bug using package inside the Processing IDE.
As you hinted in your comments, if you could compile a .jar in your Java IDE of choice and use that in Processing that should work.
From a pragmatic point of view, if you don't plan on fixing the Processing IDE to handle package as expected, you can simply not use it your code:
import processing.core.PApplet;
public class Controller {
private PApplet engine;
public Controller(PApplet engine) {
this.engine = engine;
}
public void render(){
engine.background(255,0,0);
}
}
Controller controller;
void setup(){
size(600,800, JAVA2D);
background(0);
controller = new Controller(this);
}
void draw(){
controller.render();
}
This wouldn't be convenient on a larger project where you may want to write Java code in your preferred IDE but still be able to colaborate with others that use the Processing IDE alone.
Since running in the Processing IDE works (e.g. dev/testing), but can't export a .exe for easy deployment, a workaround could be using the processing-java command. (If you add your Processing installation folder to the Windows %PATH% environment variable you should be able to type processing-java in a new Command Prompt window and see the help/usage guide).
Running processing-java --sketch=path\to\YourSketchFolder --run should run the sketch the same way the Processing IDE does (without actually having the IDE open). While this implies installing Processing and adding it to %PATH% on any new machine on one hand, on the other it saves you the time of having rebuild/repackage new .exe files for every single change.

How to package these two java classes

So right now I have two classes, one of which creates an object out of another class:
import java.io.*;
public class PostfixConverter {
public static void main(String args[]) throws IOException, OperatorException {
...
String postfixLine;
while ((postfixLine = br.readLine()) != null) {
// write some gaurd clauses for edge cases
if (postfixLine.equals("")) {
...
Cpu cpu = new Cpu();
and
public class Cpu {
Cpu() {
// this linkedListStack is for processing the postfix
...
}
Currently I'm running javac PostfixConverter.java to compile the class but it cannot find the Cpu symbol. What can I do so that the compiler can discover the missing symbol? Shouldn't everything by default be packaged in the default package and therefore find each other?
javac PostfixConverter.java
This command should work if both files are located on the current directory, as the default classpath (-cp option) is the current directory (.).
You should compile both files, so that the Cpu class file will be available to PostfixConverter:
javac Cpu.java PostfixConverter.java
Keep in mind that in general it is not desirable to build an application where everything sits in the default package. Consider creating an appropriate package here. Also, you may want to use either an IDE and/or Maven, which would make the build process easier for you.
As the other answer mentions, Java will also automatically build all Java source files in the current directory, which might explain why other source files are also getting built.

Bug in Netbeans IDE Dev 201802140002?

Here is the code that's expected to produce error:
public class App {
public static void main (String[] args) {
tick();
}
public static void tick () {
System.out.print("hi");
Note that the closing angled bracket of both, the method tick() and class App is missing. Although the IDE indicates this error while writing code, this compiles and runs just fine. It doesn't look like an issue with Java (or my OS) as doing javac in the command line surely does fail.
What's even funnier...the following code throws a Runtime exception after successfully executing tick():
public class App {
public static void main (String[] args) {
tick();
public static void tick () {
System.out.print("hello..");
Here I skipped closing bracket of main too.
I have installed the development version of Netbeans that has support for Java 9.
[This is a comment more than an answer, but I wanted to include screen shots to show that I cannot reproduce either issue.]
An interesting problem. I just downloaded the most recent nightly build (NetBeans Dev 201803060002) and built your code using Oracle JDK 9.04.
Neither of your code examples would compile for me. For the first example the error for the final line was "reached end of file while parsing System.out.print("hi");". Here is a screen shot:
For the second example, where you removed the closing bracker of main() the additional error reported was "illegal start of expression public static void tick () {":
I suggest that you try the following:
Create a new project and new class "App2" to see if you can replicate the issue with that same version of NetBeans.
If you cannot then review why App compiles and App2 does not.
If you can replicate the problem then download the most recently nightly build to see if you can still replicate the problem (i.e. Invalid source code compiles cleanly). If you cannot then I don't think it is worth raising a bug report or spending further time on the matter.
However, if you can replicate the problem then by all means raise a bug report. But I strongly recommend being able to replicate the failure before doing that. Otherwise you are likely to get a WORKSFORME response if the NetBeans team cannot replicate the issue.
One more thing: it would be helpful to update your OP with the stack trace for that RuntimeException, which you should also include in your bug report.
Ah...I see it now. At some point of time I checked the "Always run without asking" checkbox and since then my IDE is ignoring all the compile time errors without any warnings.
Sorry guys...my bad.

UnsatsifiedLinkError on JSSC Serial Interface (Processing)

I'm using Proclipsing (processing in Eclipse) but am getting an error when I try and open a port (printing the serial list works fine). I have a feeling some sort of native library is not connected but I'm baffled as to how to do so in Eclipse (and where it link to).
Here's my code:
import processing.core.PApplet;
import processing.serial.Serial;
public class visualization extends PApplet {
public Serial usb = null;
public void setup() {
println(Serial.list());
println(Serial.list()[5]);
usb = new Serial(this, Serial.list()[5], 115200);
}
public void draw() {
}
}
and the error it throws is:
Exception in thread "Animation Thread" java.lang.UnsatisfiedLinkError: jssc.SerialNativeInterface.openPort(Ljava/lang/String;Z)J
at jssc.SerialNativeInterface.openPort(Native Method)
at jssc.SerialPort.openPort(SerialPort.java:158)
at processing.serial.Serial.<init>(Unknown Source)
at processing.serial.Serial.<init>(Unknown Source)
at bioauthvisualization3.BioauthVisualization3.setup(BioauthVisualization3.java:15)
at processing.core.PApplet.handleDraw(PApplet.java:2361)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240)
at processing.core.PApplet.run(PApplet.java:2256)
at java.lang.Thread.run(Thread.java:745)
I ran into the same issue while setting up IntelliJ IDEA for development with Processing. But I imagine you can apply the same method in Proclipsing. The solution that worked for me was threefold.
I created a global library that contained the Processing and Serial libraries. In OS X the required jar files can be found in the directory /Applications/Processing.app/Contents/Java/ and /Applications/Processing.app/Contents/Java/modes/libraries/serial/library/. I added the following libraries: core.jar, serial.jarand jssc.jar.
Next I had to add the global library to my module dependencies.
The last step was to add the path to the native libraries to the VM options for the appletviewer: -Djava.library.path="/Applications/Processing.app/Contents/Java/modes/java/libraries/serial/library/macosx"
My guess is that Proclipsing does the first two steps for you but you have to add the native libraries to the vm options manually since these depend on the system you're working on. Hope that helps.
I derived the solution for step 3 from this forum entry.

Can't find symbol even though class is in the same folder

I have looked at all the other stuff, mine is a compatibility issue I think, or PATH maybe. I have a bunch of classes I've been using since about 2008 and now the java command and the javac command can't find the classes even though they are in the same directory/folder. I have C:\Program Files\Java\jdk1.6.0_25\bin in the Path variable, but nothing in the Classpath. I normally have the compiled classes in the same folder with the java I'm compiling. I've been doing the same thing for 5 years! I have recompiled the lowest level class which is called WotifCat01. The compiler comes back with
WotifCat00.java:27:cannot find symbol
Symbol : WotifCat01
import java.io.*;
/** Find/replace program **/
class WotifCat00
{
private static int cnt;
private static String[][] filnamStrg={ {"Data/reftfile.txt","Data/AccumData/allreftfile.txt","","",""},
{"Data/reft1file.txt","Data/AccumData/allreft1file.txt","","",""},
{"Data/reft2file.txt","Data/AccumData/allreft2file.txt","","",""},
{"Data/reft3file.txt","Data/AccumData/allreft3file.txt","","",""},
{"Data/reft4file.txt","Data/AccumData/allreft4file.txt","","",""},
{"Data/work1file.txt","Data/AccumData/alltextsrc.txt","","",""},
{"","","","",""} };
private static String[] args1={"","","","",""};
public static void main(String[] args) {
while (filnamStrg[cnt][0] != "") {
args1[0] = filnamStrg[cnt][0];
args1[1] = filnamStrg[cnt][1];
WotifCat01 wotifCat01 = new WotifCat01();
wotifCat01.main(args1);
cnt++;
}
}
}
I've used this setup for a while and it worked fine on my laptop till now with Windows 7. I suspect something I've installed has overwritten something. This has to be really simple but I can't see it. I've removed jdk1.7.0_25 back to 1.6 but no change.
I backed up the classpath and deleted it. Now works fine. It contained IBM DB2 paths. DB2 I had installed in 2011 so discounted it, but it did have java paths in it so it must have overrode the path. I am not sure how DB2 managed to do so 2 years after install, I may have inadvertently activated something. Thanks for your input.
Neil Mc

Categories