我在Windows上的eclipse中写了一个应用程序,我把它移到了Raspberry pi上。现在,当我尝试从eclipse运行应用程序时,我得到一个错误。 /opt/jre/jdk1.8.0_101/bin/java: 1: /opt/jre/jdk1.8.0_101/bin/java: Syntax error: end of file unexpected (expecting ")")
通过阅读其他问题,我理解这是一个解析错误,我应该在某些东西上运行dos2unix。究竟我该怎么办呢?其他问题主要与脚本有关。我有.java文件,.css文件和.fxml文件。
我之前成功地移动了.java文件并且它们运行良好。
编辑按要求发布的代码
`package Lasercontroller;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import jfxtras.scene.control.CalendarPicker;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.StackPane;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
import gnu.io.CommPortIdentifier;
public class LaserControllerUI extends Application {
public TwoWaySerialComm twoWaySerCom;
/**************************************************************************************************************************
* Initialise TwoWaySerialCom class
**************************************************************************************************************************/
public LaserControllerUI() {
twoWaySerCom = new TwoWaySerialComm();
}
/**************************************************************************************************************************
* Initialise buttons and Components
**************************************************************************************************************************/
@FXML
TextField userId, passwordfield;
@FXML
TextArea customStringTextArea, resultsTextArea;
@FXML
private Button openComportButton, setPresetButton, callPresetButton, startTourButton, stopTourButton,
clearPresetButton, upButton, downButton, leftButton, rightButton, sendCustomStringButton, dateTimePickerStart, dateTimePickerEnd;
@FXML
private Label startTimeLabel, endTimeLabel;
@FXML
private ComboBox<String> baudRateComboBox, dataBitsComboBox, stopBitsComboBox, parityComboBox, comPortComboBox;
@FXML
private ComboBox<Byte> setPresetComboBox, getPresetComboBox;
@FXML
private void initialize() {
// called by FXMLLoader after injecting fields
parityComboBox.getItems().addAll(parity);
parityComboBox.setValue("none");
baudRateComboBox.getItems().addAll(baudRates);
baudRateComboBox.setValue("4800");
dataBitsComboBox.getItems().addAll(dataBits);
dataBitsComboBox.setValue("8");
stopBitsComboBox.getItems().addAll(stopBits);
stopBitsComboBox.setValue("1");
setPresetComboBox.getItems().addAll(preset);
getPresetComboBox.getItems().addAll(preset);
comPortComboBox.getItems().addAll(comPorts);
redirectSystemStreams();
}
/**************************************************************************************************************************
* Create Stage
**************************************************************************************************************************/
@Override
public void start(Stage primaryStage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("LaserControllerUI.fxml"));
Scene scene = new Scene(root);
primaryStage.setTitle("Laser Controller");
primaryStage.setScene(scene);
primaryStage.show();
scene.getStylesheets().add(LaserControllerUI.class.getResource("LaserControllerUI.css").toExternalForm());
// getClass().getResource("resources/Airport.jpg");
}
public static void main(String[] args) {
launch(args);
}
/**************************************************************************************************************************
* Open, Close and check available Comports
**************************************************************************************************************************/
@FXML
private void checkComPorts() {
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier cpi = (CommPortIdentifier) portList.nextElement();
if (cpi.getPortType() == CommPortIdentifier.PORT_SERIAL) {
comPortComboBox.getItems().addAll(cpi.getName());
System.out.println(portList);
}
}
}
@FXML
public void openComportButton(ActionEvent event) {
resultsTextArea.setText("Com Port Opened");
String port = (String)comPortComboBox.getValue();
//String port = "COM4";
String rate = (String) baudRateComboBox.getValue();
String data = (String) dataBitsComboBox.getValue();
String stop = (String) stopBitsComboBox.getValue();
int parity = (int) parityComboBox.getSelectionModel().getSelectedIndex();
int rateInt = Integer.parseInt(rate);
int dataInt = Integer.parseInt(data);
int stopInt = Integer.parseInt(stop);
if (port != null && rate != null && data != null && stop != null) {
try {
twoWaySerCom.connect(port, rateInt, dataInt, stopInt, parity);
} catch (Exception e) {
e.printStackTrace();
}
}
}
@FXML
public void closeComportButton(ActionEvent event) {
resultsTextArea.setText("Com Port Closed");
try {
twoWaySerCom.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
/**************************************************************************************************************************
* Up/Down/Left/Right Buttons
*
**************************************************************************************************************************/
@FXML
public void leftButtonPressed(){
try {
System.out.println("Left Button pressed, String: " + leftString);
byte[] command = { (byte) startTx, address, byteOne, panLeft, speedNormal, 0x00, endTx, 0x2B };
TwoWaySerialComm.SerialWriter sw = new TwoWaySerialComm.SerialWriter(
twoWaySerCom.serialPort.getOutputStream());
sw.out.write(command);
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
public void leftButtonReleased(){
try {
System.out.println("Left Button released, String: " + stopString);
byte[] command = {
(byte) startTx, address, byteOne, 0x00, 0x00, 0x00, (byte) endTx, 0x0F
};
TwoWaySerialComm.SerialWriter sw = new TwoWaySerialComm.SerialWriter(
twoWaySerCom.serialPort.getOutputStream());
sw.out.write(command);
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
public void rightButtonPressed(){
try {
System.out.println("right Button pressed, String: " + leftString);
byte[] command = { (byte) startTx, address, byteOne, panRight, speedNormal, 0x00, endTx, 0x2B };
TwoWaySerialComm.SerialWriter sw = new TwoWaySerialComm.SerialWriter(
twoWaySerCom.serialPort.getOutputStream());
sw.out.write(command);
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
public void rightButtonReleased(){
try {
System.out.println("right Button released, String: " + stopString);
byte[] command = {
(byte) startTx, address, byteOne, 0x00, 0x00, 0x00, (byte) endTx, 0x0F
};
TwoWaySerialComm.SerialWriter sw = new TwoWaySerialComm.SerialWriter(
twoWaySerCom.serialPort.getOutputStream());
sw.out.write(command);
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
public void upButtonPressed(){
try {
System.out.println("Up Button pressed, String: " + leftString);
byte[] command = { (byte) startTx, address, byteOne, panUp, speedNormal, 0x00, endTx, 0x2B };
TwoWaySerialComm.SerialWriter sw = new TwoWaySerialComm.SerialWriter(
twoWaySerCom.serialPort.getOutputStream());
sw.out.write(command);
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
public void upButtonReleased(){
try {
System.out.println("Up Button released, String: " + stopString);
byte[] command = {
(byte) startTx, address, byteOne, 0x00, 0x00, 0x00, (byte) endTx, 0x0F
};
TwoWaySerialComm.SerialWriter sw = new TwoWaySerialComm.SerialWriter(
twoWaySerCom.serialPort.getOutputStream());
sw.out.write(command);
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
public void downButtonPressed(){
try {
System.out.println("Down Button pressed, String: " + leftString);
byte[] command = { (byte) startTx, address, byteOne, panDown, speedNormal, 0x00, endTx, 0x2B };
TwoWaySerialComm.SerialWriter sw = new TwoWaySerialComm.SerialWriter(
twoWaySerCom.serialPort.getOutputStream());
sw.out.write(command);
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
public void downButtonReleased(){
try {
System.out.println("Down Button released, String: " + stopString);
byte[] command = {
(byte) startTx, address, byteOne, 0x00, 0x00, 0x00, (byte) endTx, 0x0F
};
TwoWaySerialComm.SerialWriter sw = new TwoWaySerialComm.SerialWriter(
twoWaySerCom.serialPort.getOutputStream());
sw.out.write(command);
} catch (IOException e) {
e.printStackTrace();
}
}
/**************************************************************************************************************************
* Start Stop Buttons
*
****************************************************************************** ********************************************/
@FXML
public void startTourButton(ActionEvent event) {
new Timer ().schedule(
new TimerTask () {
@Override
public void run() {
try{
byte st = presetNo[count];
System.out.println( "Start Tour Button pressed, String: "+st);
//this part will run from 0 to max of presets every counting.
count ++;
if (count >=MaxCount) count=0;
byte[] command = {(byte) startTx, address, byteOne, goPreset, 0x00, st, endTx, 0x0F};
TwoWaySerialComm.SerialWriter sw = new TwoWaySerialComm.SerialWriter(
twoWaySerCom.serialPort.getOutputStream());
sw.out.write(command);
}
catch (IOException e) {
e.printStackTrace();
}
}
}, 0, 5000);
}
public void stopTourButton(ActionEvent event) {
// Timer.cancel();
}
/**************************************************************************************************************************
* Call and Set Preset Buttons
**************************************************************************************************************************/
@FXML
public void setPresetButton(ActionEvent event) {
byte _preset = (Byte) setPresetComboBox.getValue();
try {
something = presetNo[_preset - 1];
byte[] command = { (byte) startTx, address, byteOne, setPreset, 0x00, something, endTx, 0x0F };
TwoWaySerialComm.SerialWriter sw = new TwoWaySerialComm.SerialWriter(
twoWaySerCom.serialPort.getOutputStream());
sw.out.write(command);
System.out.println(something);
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
public void callPresetButton(ActionEvent event) {
byte _preset = (byte) getPresetComboBox.getValue();
try {
something = presetNo[_preset - 1];
byte[] command = { (byte) startTx, address, byteOne, goPreset, 0x00, something, endTx, 0x0F };
TwoWaySerialComm.SerialWriter sw = new TwoWaySerialComm.SerialWriter(
twoWaySerCom.serialPort.getOutputStream());
System.out.println(something);
sw.out.write(command);
} catch (IOException e) {
e.printStackTrace();
}
}
/**************************************************************************************************************************
* Date Time Picker for the start date
**************************************************************************************************************************/
@FXML
public void dateTimePickerStart(){
CalendarPicker dateTime = new CalendarPicker();
dateTime.withCalendar(Calendar.getInstance());
dateTime.withShowTime(Boolean.TRUE);
dateTime.withLocale(Locale.ENGLISH);
dateTime.calendarProperty().addListener(new ChangeListener<Calendar>() {
public void changed(ObservableValue<? extends Calendar> ov, Calendar t, Calendar t1) {
System.out.println("Selected date: "+t1.getTime().toString());
startTimeLabel.setText(t1.getTime().toString());
}
});
StackPane root = new StackPane();
root.getChildren().add(dateTime);
Scene scene = new Scene(root, 400, 350);
Stage stage = new Stage();
stage.setTitle("Select Time");
stage.setScene(scene);
stage.show();
}
/**************************************************************************************************************************
* Date Time Picker for the end date
**************************************************************************************************************************/
@FXML
public void dateTimePickerEnd(){
CalendarPicker dateTime = new CalendarPicker();
dateTime.withCalendar(Calendar.getInstance());
dateTime.withShowTime(Boolean.TRUE);
dateTime.withLocale(Locale.ENGLISH);
dateTime.calendarProperty().addListener(new ChangeListener<Calendar>() {
public void changed(ObservableValue<? extends Calendar> ov, Calendar t, Calendar t1) {
System.out.println("Selected date: "+t1.getTime().toString());
endTimeLabel.setText(t1.getTime().toString());
}
});
StackPane root = new StackPane();
root.getChildren().add(dateTime);
Scene scene = new Scene(root, 350, 350);
Stage stage = new Stage();
stage.setTitle("Select Time");
stage.setScene(scene);
stage.show();
}
/**************************************************************************************************************************
* to Redirect System Streams to the text area
**************************************************************************************************************************/
@FXML
public void redirectSystemStreams() {
OutputStream out = new OutputStream() {
@Override
public void write(int b) throws IOException {
updateTextArea(String.valueOf((char) b));
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
updateTextArea(new String(b, off, len));
}
@Override
public void write(byte[] b) throws IOException {
write(b, 0, b.length);
}
};
System.setOut(new PrintStream(out, true));
System.setErr(new PrintStream(out, true));
}
public void updateTextArea(final String text) {
Platform.runLater(new java.lang.Runnable() {
public void run() {
resultsTextArea.appendText(text);
}
});
}
String stopString = "A0,00,00,00,00,00,AF,0F";
String downString = "A0,00,00,10,20,00,AF,2B";
String leftString = "A0,00,00,04,20,00,AF,2B";
String rightString = "A0, 00,00,02,20,00,AF,2B";
String upString = "A0,00,00,08,20,00,AF,2B";
String[] comPorts = {"COM1", "COM2", "COM3", "COM4", "COM5", "COM6","COM7", "COM7", "COM9", "COM10",};
String[] parity = { "none", "odd", "even", };
String[] baudRates = { "2400", "4800", "9600", "14400", "19200", "38400", "56000", "115200" };
String[] stopBits = { "0", "1" };
String[] dataBits = { "7", "8" };
byte presetNo[] = { 0X01, 0X02, 0X03, 0X04, 0X05 };
byte something;
Byte[] preset = { 1, 2, 3, 4, 5 };
int count = 0;
int MaxCount = presetNo.length;
byte startTx = (byte) 0xA0;
byte endTx = (byte) 0xAF;
byte address = 0x00;
byte byteOne = 0x00;
byte setPreset = 0x03;
byte goPreset = 0x07;
byte panRight = 0x02;
byte panLeft = 0x04;
byte panUp = 0x08;
byte panDown = 0x10;
byte speedNormal = 0x20;
}
答案 0 :(得分:0)
/opt/jre/jdk1.8.0_101/bin/java: 1: /opt/jre/jdk1.8.0_101/bin/java: Syntax error: end of file unexpected (expecting ")")
这不是程序中的错误,而是JDK安装中的错误。听起来像/opt/jre/jdk1.8.0_101/bin/java
是一个无效的shell脚本 - 这有点奇怪,因为至少在x86_64 Oracle JDK上,这应该是二进制可执行文件,而不是脚本。
我建议为您的计算机重新安装正确的JDK。