So I've been learning how to use JavaFX in Eclipse, and have come across a character encoding error that always occurs on the last character before the class declaration.
Whenever I run the script, a program error appears that says exactly this:
"Save could not be completed. Try File > Save As... if the problem persists. Reason: Some characters cannot be mapped using the "Cp1252" character encoding. Either change the encoding or remove the characters which are not supported by the "Cp1252" character encoding."
I have tried downloading a different program that supports FX called IntelliJ IDEA, and the same error happened on that program, too. However, I somehow managed to fix this error on IntelliJ by simply rewriting the last import by hand. Unfortunately, fixing this problem didn't seem to be as simple when I used Eclipse. The reason I am using Eclipse instead of just using IntelliJ is that my school computers only use 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();
}
}
It sounds like somehow you are getting a character in the file which can't be represented in the Cp1252 encoding (which can only deal with a limited range of characters).
You could change the encoding of the file to UTF-8 which can deal with just about anything.
To change a single file open the file Properties and the Resource page change the 'Text file encoding' value to UTF-8.
You can also change the default text file encoding for the workspace in the Preferences on the 'General > Workspace' page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With