I have that java class. It's initialized in JavaClassContainer
. The problem is that it returns that error: java.lang.NullPointerException
. A no set the text to the textfield
.
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import gnu.io.SerialPortEvent;
import gnu.io.SerialPortEventListener;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Enumeration;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
public class RXTX implements SerialPortEventListener{
@FXML private static TextField carlos;
// MORE CODE
@FXML
private void GetData(String Data) {
if(Data.contains("Temperature")){
carlos.setText("Hola");
}
}
}
If I put a System.Out.Println for instance it works. So, The problem is in the setText
to the TextField
no in GetData
class.
Ok, I will put also the main controller:
public class FXMLDocumentController implements Initializable {
@FXML
private Label label;
@FXML
private void handleButtonAction(ActionEvent event) {
System.out.println("You clicked me!");
label.setText("Hello World!");
}
@Override
public void initialize(URL url, ResourceBundle rb) {
RXTX main = new RXTX();
main.initialize();
Thread t=new Thread() {
public void run() {
//the following line will keep this app alive for 1000 seconds,
//waiting for events to occur and responding to them (printing incoming messages to console).
try {Thread.sleep(1000000);} catch (InterruptedException ie) {}
}
};
t.start();
System.out.println("Started");
}
}