Eclipse Could not find or load main class - java

Have been trying to set up JavaFX with Eclipse on Ubuntu. The code doesn't have an issue importing the javafx classes anymore (this took a LONG time to get working), but when running some simple test code, Eclipse can't seem to find the main class even when I right click on the file directly and run as Java Application.
package mainpackage;
import javafx.application.Application;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Window");
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
Error: Could not find or load main class mainpackage.Main
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

Related

Importing javaFX (.jar) files into a Netbeans Maven Project

I am trying to import javafx (.jar) files into a maven project. I have made a project with Netbeans (Java with Ant -> Java Application) and want to use the same code in Netbeans (Java with Maven -> Java Application). With Ant, I can easily import and use the (.jar) files, but this seems to be a blocked functionality with Maven.
Any solution to this?
I have looked up on several posts and guides online with no luck.
NOTE: Implementing .jar files within maven have been solved. The code does not work though.
Current Error: "Exception running application com.mycompany.ep_game_ref.Game Command execution failed."
package com.mycompany.ep_game_ref;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.image.Image;
import javafx.stage.Stage;
public class Game extends Application
{
public static String[] args;
public static Stage primarystage;
public static ObservableList<Items.Item> items = FXCollections.observableArrayList();
public static MainCentral startGame = new MainCentral();
public static Room.Introduction intro = new Room.Introduction();
public static Settings.Difficulty SETTINGS = new Settings.Difficulty();
public static Player player = new Player();
#Override
public void start(Stage stage)
{
this.primarystage = stage;
this.primarystage.setScene(new Scenes.Welcome().setWelcomeScene());
this.primarystage.getIcons().add(new Image("images/aq_logo.png"));
this.primarystage.setResizable(false);
this.primarystage.show();
}
public static void main(String[] args) {
Application.launch();
}
}
You can use JavaFX in a different way:
File>New Project>Maven>JavaFX Application.

How to Fix NoClassDefFoundError in JavaFX?

I'm trying to build a small user interface using JavaFX, But I'm getting an error like this:
Error: Could not find or load main class myApp Caused by:
java.lang.NoClassDefFoundError: javafx/application/Application
This is my code:
and im using jdk 12.0.2
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class myApp extends Application{
public static void main(String[] args) {
Phonebook mybook = new Phonebook();
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
Group group = new Group();
Scene scene = new Scene(group, 600, 300);
scene.setFill(Color.GRAY);
primaryStage.setTitle("Phone Book");
primaryStage.setScene(scene);
primaryStage.show();
}
This is the Libraries and jdk I'm using:
Image1
I think JavaFX is not a part of the JDK > 9 any more. (Your version is 12.x.x)
Probably this could help you:
https://openjfx.io/openjfx-docs/#install-javafx
(Assuming you are using Maven) If this does not help, try to clean and build your Application.
Sometimes Maven does not recognize newly added dependencies.

javafx import cannot be resolved in eclipse

I am starting an assignment and just installed javafx from the Eclipse marketplace, after I installed and created a javafx project with fxml however in main the imports are showing errors saying "the import javafx cannot be resolved". I am new to Java and Eclipse and have tried to search for similar questions but they all seem to be different cases.
I would appreciate any help thank you.
Below is the code, and all the imports are showing errors:
package application;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.fxml.FXMLLoader;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
BorderPane root = (BorderPane)FXMLLoader.load(getClass().getResource("Student.fxml"));
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
I have figured that it is the library JavaFx SDK which is not able to be added to the project, is anyone good with Eclipse can help solve this problem? I tried configure build path and removing the JavaFx SDK and readding, still does not work.

Using package while running; Error "Could not find or load main class"

classpath= C:\Program Files\Java\jdk1.8.0_111\jre\lib\;C:\Program Files\Java\jdk1.8.0_111\bin;
path=C:\Program Files\Java\jdk1.8.0_111\bin;C:\Program Files\Java\jre1.8.0_111\bin;
package seleniumTest;
public class SampleTest {
public static void main(String[] args)
{
System.out.println("hello");
}
}
My question is I am not able run the Java file while using the package.
I am new to Java so not able to find the root cause. Please help me out.
Its not able to reach the main class.

ControlsFX 8.0.6 dialogs java.util.MissingResourceException

I'm a new user of ControlsFX and I have an issue that I don't understand:
My code:
Dialogs.create()
.owner(mainStage)
.title("Information Dialog")
.masthead("Test masthead")
.message("Test message")
.showInformation();
And I obtain an exception:
Exception in thread "JavaFX Application Thread" java.util.MissingResourceException: Can't find bundle for base name impl.org.controlsfx.dialog.resources.oxygen.dialog-resources, locale fr_FR
Does anybody have an idea why this happens?
Thank you.
Did you download the right JAR ? Aka this: ControlsFX-8.0.6
Because I'm made this simplest program with the JAR I specified and I got no errors:
import javafx.application.Application;
import javafx.stage.Stage;
import org.controlsfx.dialog.Dialogs;
public class Test extends Application {
#Override
public void start(Stage primaryStage) {
Dialogs.create()
.owner(primaryStage)
.title("Information Dialog")
.masthead("Test masthead")
.message("Test message")
.showInformation();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Please also consider to raise your question in the official group support here : http://groups.controlsfx.org , you'll likely have more answers.

Categories