Problems working with values from String.split

isi_ko :

for my current project i need to communicate with an arduino via USB and i use csv. What do I mean by this? Let me try to explain it. I want to use the Arduino to read sensors. But since I have different sensors, I want to send more than just the value in a message, but also which sensor the value comes from and what kind of sensor it is (button, potentiometer, ...).I also have different kinds of things that should trigger the messages, e.g. sending the value of a sensor or moving a motor. I then separate these data from each other by semicolons. When the message arrives at Java, Java splits the String with String.split(";"). My problem is that the first number is not recognized correctly by Java. If I do not comment out the code that is currently commented out in Java, the code in the IF statement is no longer executed, even if the code in the else is always printing out

"1"

This is interesting, because currently args[0] can't be anything else than 1 (as seen in the Arduino Code), and obviously it isn't.

Hope you can help me.

isi_ko

Java Code: https://pastebin.com/vx0LdpuE
Arduino Code: https://pastebin.com/bgFMiQyt
Šimon Kocúrek :

Instead of:

if (args[0] == "1"){

Do:

if ("1".equals(args[0])) {

String is an object and therefore == compares references and not value.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=301175&siteId=1