0

So I'm trying to work on a project and can't get JavaFX to work through Eclipse to save my life. I've tried reconfiguring it, rebuilding the project, reinstalling eclipse and redownloading the JavaFX SDKs multiple times, added like 3 new user libraries of re-downloaded jar files, etc and keep getting the same error, even with the stock "Main" class that comes with the new project. I'm totally stumped. Here is the mess I am looking at:

Here is the code for my application that I am trying to test:

package application;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class StartupBrowser extends Application {
    private BorderPane root;
    private BorderPane browserContentHolder;
    private WebView webView;
    private WebEngine webEngine;
    private HBox addressBar;
    private HBox statusBar;
    private Text domain;
    private Text copyright;
    private Text currentDate;
    private Text currentTime;
    private Text separator;
    private final String homePage = "https://langara.ca";

    private void setupAddressBar() {
        addressBar = new HBox();
        Button home = new Button("", new ImageView(new Image("home.png")));
        TextField url = new TextField();
        addressBar.getChildren().addAll(home, url);
    }

    private void setupStatusBar() {
        statusBar = new HBox();
        domain = new Text("langara.ca");
        separator = new Text("|");
        separator.setStyle("-fx-padding: 0 5 0 5;");
        currentDate = new Text();
        currentDate.setStyle("-fx-padding: 0 5 0 5;");
        currentTime = new Text();
        currentTime.setStyle("-fx-padding: 0 5 0 5;");
        updateDateTime();
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("EEE, MMM dd, yyyy");
        DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("hh:mm:ss a");
        currentDate.setText(dateFormatter.format(LocalDateTime.now()));
        currentTime.setText(timeFormatter.format(LocalDateTime.now()));
        copyright = new Text("JavaFX -- All Rights Reserved.");
        statusBar.getChildren().addAll(domain, separator, currentDate, currentTime, separator, copyright);
        statusBar.setAlignment(Pos.CENTER_RIGHT);
    }

    private void updateDateTime() {
        DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("hh:mm:ss a");
        currentTime.setText(timeFormatter.format(LocalDateTime.now()));
    }

    private void setupBrowserContentHolder() {
        browserContentHolder = new BorderPane();
        webView = new WebView();
        webEngine = webView.getEngine();
        webEngine.load(homePage);
        browserContentHolder.setCenter(webView);
    }

    public void start(Stage stage) {
        root = new BorderPane();
        this.setupAddressBar();
        this.setupBrowserContentHolder();
        this.setupStatusBar();
        root.setTop(addressBar);
        root.setBottom(statusBar);
        root.setCenter(browserContentHolder);
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setWidth(1200);
        stage.setHeight(1000);
        stage.setResizable(false);
        stage.setTitle("JavaFX Browser");
        stage.show();
    }

    public static void main(String[] args) {
        Application.launch(args);
    }
}

and the error:

Error: Could not find or load main class application.StartupBrowser
Caused by: java.lang.ClassNotFoundException: application.StartupBrowser

And project structure:

enter image description here

As you can see it's a mess from me trying to redo the user libraries so many times. How do I get this to quit throwing this error so I can finally test my project?

AstralV
  • 119
  • 7
  • 2
    Post code as text formatted as code not as a screenshot. Same for error messages and stack traces. – jewelsea Apr 07 '23 at 19:36
  • 2
    There is no `package application;` statement in the code image you show. – jewelsea Apr 07 '23 at 19:37
  • 1
    If you have been stuck for a long time, try a different approach. To quickly get started, I advise downloading idea and using the [new JavaFX project wizard](https://stackoverflow.com/questions/74764217/error-javafx-runtime-components-are-missing-with-intellij-idea-maven-and-jdk/74764297#74764297). – jewelsea Apr 07 '23 at 19:42
  • I have idea but wasn't sure how to get my own code to work in it, i edited the first post to reflect what i'm working on – AstralV Apr 07 '23 at 19:52
  • 1
    Just follow the instructions I linked. Otherwise, openjfx.io has getting started instructions for all major IDEs. – jewelsea Apr 07 '23 at 20:03
  • 1
    It is not your issue currently, but the javafx.web module requires additional setup. You can find info on that on StackOverflow. First though, get the basic HelloWorld app from openjfx.io getting started or the idea new JavaFX wizard working without WebView. – jewelsea Apr 07 '23 at 20:09
  • yeah i have the same issue with the regular HelloWorld app it sucks :( but i guess ill try to use Idea instead – AstralV Apr 07 '23 at 20:20
  • k now i'm at the javafx.web step haha. i'll look thru stackoverflow for resources – AstralV Apr 07 '23 at 22:11

0 Answers0