Java FX - Cp1252 字符编码错误

3 java eclipse encoding javafx intellij-idea

所以我一直在学习如何在 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();
    }
}
Run Code Online (Sandbox Code Playgroud)

gre*_*449 7

听起来好像你在文件中得到了一个不能用 Cp1252 编码表示的字符(它只能处理有限范围的字符)。

您可以将文件的编码更改为 UTF-8,它几乎可以处理任何事情。

要更改单个文件,请打开文件属性,然后在资源页面将“文本文件编码”值更改为 UTF-8。

您还可以在“常规 > 工作区”页面上的首选项中更改工作区的默认文本文件编码。