【问题标题】:Why do I have java.lang.ClassNotFoundException while trying to run JavaFx application?为什么在尝试运行 JavaFx 应用程序时出现 java.lang.ClassNotFoundException?
【发布时间】:2012-01-20 18:27:08
【问题描述】:

我已尝试按照here 的描述创建示例应用程序,代码如下:

package colorfulcircles;

import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.effect.BlendMode;
import javafx.scene.effect.BoxBlur;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.StrokeType;
import javafx.stage.Stage;
import javafx.util.Duration;
import static java.lang.Math.random;


public class ColorfulCircles 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, 800, 600, Color.BLACK);
        primaryStage.setScene(scene);
        Group circles = new Group();
        for (int i = 0; i < 30; i++) {
            Circle circle = new Circle(150, Color.web("white", 0.05));
            circle.setStrokeType(StrokeType.OUTSIDE);
            circle.setStroke(Color.web("white", 0.16));
            circle.setStrokeWidth(4);
            circles.getChildren().add(circle);
        }
        Rectangle colors = new Rectangle(scene.getWidth(), scene.getHeight(),
                new LinearGradient(0f, 1f, 1f, 0f, true, CycleMethod.NO_CYCLE, new Stop[]{
                    new Stop(0, Color.web("#f8bd55")),
                    new Stop(0.14, Color.web("#c0fe56")),
                    new Stop(0.28, Color.web("#5dfbc1")),
                    new Stop(0.43, Color.web("#64c2f8")),
                    new Stop(0.57, Color.web("#be4af7")),
                    new Stop(0.71, Color.web("#ed5fc2")),
                    new Stop(0.85, Color.web("#ef504c")),
                    new Stop(1, Color.web("#f2660f")),}));
        Group blendModeGroup =
                new Group(new Group(new Rectangle(scene.getWidth(), scene.getHeight(),
                     Color.BLACK), circles), colors);
        colors.setBlendMode(BlendMode.OVERLAY);
        root.getChildren().add(blendModeGroup);      
        circles.setEffect(new BoxBlur(10, 10, 3));
        Timeline timeline = new Timeline();
        for (Node circle : circles.getChildren()) {
            timeline.getKeyFrames().addAll(
                    new KeyFrame(Duration.ZERO, // set start position at 0
                    new KeyValue(circle.translateXProperty(), random() * 800),
                    new KeyValue(circle.translateYProperty(), random() * 600)),
                    new KeyFrame(new Duration(40000), // set end position at 40s
                    new KeyValue(circle.translateXProperty(), random() * 800),
                    new KeyValue(circle.translateYProperty(), random() * 600)));
        }
        // play 40s of animation
        timeline.play();
        primaryStage.show();
    }
}

为什么会出现异常? 我使用 NetBeans 7.1 RC1 这是屏幕截图。

输出:

java.lang.ClassNotFoundException: javafxapplication4.JavaFXApplication4
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at com.javafx.main.Main.getAppClass(Main.java:409)
    at com.javafx.main.Main.launchApp(Main.java:435)
    at com.javafx.main.Main.main(Main.java:537)

这个?

【问题讨论】:

  • 真的吗?发布堆栈跟踪,而不是它的屏幕截图......
  • 甚至无法读取堆栈跟踪。可能值得一提的是代码在哪个类上出错...
  • 为什么这个问题被否决了?
  • @RCola,我投了反对票,因为你已经问了 52 个问题,而且你仍然包含堆栈跟踪的屏幕截图。

标签: java netbeans javafx


【解决方案1】:

根据我在此屏幕截图中看到的内容进行的猜测:您重命名了应用程序的主类,而 Netbeans 仍在寻找旧的类名来运行它?

尝试右键单击您的项目,然后在弹出的窗口中查看“运行”下的“主类”。

否则,请发布堆栈跟踪本身,而不是屏幕截图。

【讨论】:

  • 项目属性> 运行> 应用程序类:“javafxapplication4.JavaFXApplication4”
  • 你的猜测是正确的。我重命名了它,但我还必须执行以下操作:项目属性>运行>应用程序类:这里更改为新类!
猜你喜欢
  • 1970-01-01
  • 2015-06-23
  • 2020-02-08
  • 1970-01-01
  • 1970-01-01
  • 2011-10-30
  • 1970-01-01
  • 2021-01-20
  • 1970-01-01
相关资源
最近更新 更多