每当我通过web-> css或javafx项目创建一个css文件时,我都会得到同样的错误
Multiple markers at this line
- Syntax error on token "Invalid Character", interface expected
- Syntax error, insert "InterfaceBody" to complete CompilationUnit
我搜索了解决方案,但他们通常喜欢通过web-> css创建一个新的css文件,但这对我没有帮助。 我进一步研究,我发现bin中没有css的输出文件。现在我不知道该怎么办。任何人都可以帮助我吗? 这是我的代码(eclipse Neon):
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
System.out.println("aaaa");
Parent root=FXMLLoader.load(getClass().getResource("/application/Main.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
primaryStage.setTitle("pvrock");
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
application.css
#label{
-fx-font-size:30px;
}
Main.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="300" prefWidth="400" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.60" fx:controller="application.MainController">
<children>
<Button fx:id="btn1" layoutX="169.0" layoutY="198.0" mnemonicParsing="false" onAction="#f1" prefHeight="23.0" prefWidth="62.0" text="Click me">
<font>
<Font size="10.0" />
</font>
</Button>
<Label fx:id="label" layoutX="146.0" layoutY="112.0" prefHeight="78.0" prefWidth="120.0" />
</children>
</AnchorPane>
MainController.java
package application;
import java.util.Random;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
public class MainController {
@FXML
private Label label;
public void f1(ActionEvent event){
Random rand=new Random();
int num=rand.nextInt(50)+1;
System.out.println(num);
label.setText(Integer.toString(num));
}
}
错误的屏幕截图: Compilation error