因此,我一直在学习如何在Eclipse中使用JavaFX,并且遇到了一个字符编码错误,这个错误总是发生在类声明之前的最后一个字符上。
每当我运行脚本时,就会出现一个程序错误,其内容如下:
“保存无法完成。如果问题仍然存在,请尝试文件>另存为.。原因:一些字符不能使用"Cp1252”字符编码进行映射。要么更改编码,要么删除"Cp1252“字符编码不支持的字符。”
我尝试下载了一个不同的程序,它支持FX,叫做IntelliJ IDEA,同样的错误也发生在这个程序上。但是,我通过手工重写最后一个导入,设法在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();
}
}发布于 2017-06-02 20:40:10
听起来好像文件中有一个不能用Cp1252编码表示的字符(它只能处理有限的字符范围)。
您可以将文件的编码更改为UTF-8,这几乎可以处理任何事情。
若要更改单个文件,请打开文件属性,资源页将“文本文件编码”值更改为UTF-8。
您还可以在'General > Workspace‘页面的首选项中更改工作区的默认文本文件编码。
发布于 2021-03-03 14:09:30
例如:
我发现问题的起因是一个特殊的角色:
在我的代码中的某个地方写的是:
//Now blabla Equation n̊1其中n̊1导致了“保存问题”错误
https://stackoverflow.com/questions/44336715
复制相似问题