我一直在学习如何在Eclipse中使用JavaFX,并遇到一个字符编码错误,该错误总是发生在类声明之前的最后一个字符。
每当我运行脚本时,都会出现一个程序错误,其内容如下:
"无法完成保存。如果问题仍然存在,请尝试选择文件 > 另存为... 原因: 某些字符无法使用"Cp1252"字符编码映射。 要么更改编码,要么删除不受"Cp1252"字符编码支持的字符。"
我尝试下载了一个名为IntelliJ IDEA的支持FX的不同程序,但该程序也出现了同样的错误。但是,在IntelliJ中,我通过手动重写最后一个导入项来修复了此错误。不幸的是,在使用Eclipse时,解决这个问题似乎并不简单。我之所以使用Eclipse而不仅仅使用IntelliJ,是因为我的学校计算机只使用Eclipse。
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox; //error appears after the semicolon on this line
public class Main extends Application {
Scene s1, s2;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage window) {
Label label1 = new Label("s1");
Button button1 = new Button("Click for s2");
button1.setOnAction(e -> window.setScene(s2));
VBox lay1 = new VBox(50);
lay1.getChildren().addAll(label1, button1);
s1 = new Scene(lay1, 500, 500);
Button button2 = new Button("Click for s1");
button2.setOnAction(e -> window.setScene(s1));
s2 = new Scene(lay1, 300, 250);
window.setScene(s1);
window.setTitle("title");
window.show();
}
}