我正在使用它
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Group root = new Group();
Scene scene = new Scene(root, 600, 400);
primaryStage.setScene(scene);
Circle circle = new Circle(300,200,50, Color.BLACK);
primaryStage.setTitle("Circle");
primaryStage.setResizable(false);
root.getChildren().add(circle);
moveCircle(circle, scene);
primaryStage.show();
}
public int random(int min, int max) {
return new Random().nextInt((max - min) + …Run Code Online (Sandbox Code Playgroud) 我收到此错误:
Caused by: java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\Users\Emre\Desktop\PN1g1z.gif
Run Code Online (Sandbox Code Playgroud)
而且我真的不知道什么是错的.
这是抛出异常的原因:
Media media = new Media(file.getAbsolutePath());
Run Code Online (Sandbox Code Playgroud) 当我尝试运行我的应用程序时,我收到此错误:
Caused by: java.lang.NullPointerException
at WebOpenController.<init>(WebOpenController.java:19)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:438)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:923)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:967)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2701)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2521)
... 22 more
Run Code Online (Sandbox Code Playgroud)
第19行是这个私有的WebEngine engine = view.getEngine();
这是班级:
public class WebOpenController implements Initializable {
@FXML
private WebView view;
private String link = "http://google.com";
private WebEngine engine = view.getEngine();
@Override
public void initialize(URL location, ResourceBundle resources) {
engine.load(link);
}
Run Code Online (Sandbox Code Playgroud)
但是,当我做WebView view = new WebView时它会工作,但它不会在启动时打开页面
我确实在scenebuilder中设置了fx-id