JavaFX ListView Null Pointer when Adding to List [duplicate] - java

This question already has answers here:
Passing Parameters JavaFX FXML
(10 answers)
Closed 3 years ago.
Edit: Static's removed. Still getting the same error
I've created a GUI with a Listview in Scene builder and now I'm trying to populate the Listview with some Strings.
I'm using 2 classes at the moment. Here are 2 cut down versions of the scripts for easier reading
MainController:
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class MainController extends Application
{
#Override
public void start(Stage primaryStage) throws Exception
{
Parent root = FXMLLoader.load(getClass().getResource("IntelligentSystems.fxml"));
primaryStage.setTitle("Intelligent Systems Agent Program");
primaryStage.setScene(new Scene (root));
primaryStage.show();
GUIController GUIList = new GUIController();
GUIList.DoList.add("agentCtrl");
GUIList.DoList.add("DeliveryAgent");
GUIList.PopulateAgentList();
}
public static void main (String[] args)
{
launch(args);
}
}
and the second Class, GUIController:
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import javafx.collections.ObservableList;
import javafx.collections.FXCollections;
public class GUIController {
//List View variables.
#FXML
public ListView AgentsList;
#FXML
public ObservableList<String> DoList= FXCollections.observableArrayList();
#FXML
public void PopulateAgentList()
{
AgentsList.setItems(DoList);
}
}
Currently, I've set the fxId of the Listview to "AgentsList" in the fxml file.
<ListView fx:id="AgentsList" layoutX="15.0" layoutY="39.0" prefHeight="200.0" prefWidth="86.0" />
Whenever I run the program in IntelliJ, it always returns a java.lang.NullPointerException around the "AgentsList.setItems(_doList);" line.
I'm completely lost as to why it can't add to the list. Not helped that I haven't been using Java for long as I've mostly worked with C#.
Edit: Exception Stack Trace:
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.lang.NullPointerException
at GUIController.PopulateAgentList(GUIController.java:26)
at MainController.start(MainController.java:57)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Exception running application MainController
Process finished with exit code 1

Your #FXML annotated fields are static, which is not supported by JavaFX, as it is desinged to create/load multiple instances of the same fxml file/controller class. If you are unfamiliar with what 'static' actually means, you can refer to What is the difference between a static method and a non-static method?.
As for how you get the correct controller instance, you need to load the fxml file a little bit different.
FXMLLoader loader = new FXMLLoader(getClass().getResource("IntelligentSystems.fxml"));
Parent root = loader.load(); // must be called before getting the controller!
GUIController controller = loader.getController();
Now you can use the controller variable to access the fields in a non-static way.

Related

Cannot invoke "Object.getClass()" because "obj" is null - JavaFX [duplicate]

So basically I began a dummy JavaFX project just to achieve a minimalistic example for my actual problem. But now I am not even able to run that minimalistic project anymore and do not receive enough error information to actually google it myself out. So right now, when I run the code, I receive the given error stack, which does not lead me anywhere.
I am using IntelliJ. JavaFX libraries are set correctly and VM Options set to:
--module-path "C:\Program Files\Java\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml
On top, when I run the code, those errors pop up in console, but the application seems to still be running, because I need to press the Red Stop Button of IntelliJ to actually stop it.
Has anyone some guess, what goes wrong here? I am not experienced enough to follow those errors, since they do not point into my code, but rather into some Deep Java code.
The Exception:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.NullPointerException
at java.base/java.lang.reflect.Method.invoke(Method.java:559)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
... 5 more
Main.java:
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import java.io.IOException;
public class Main extends Application {
private Stage rootStage;
public BorderPane mainWindow;
public AnchorPane left;
public AnchorPane bottom;
#Override
public void start(Stage primaryStage) throws Exception {
this.rootStage = primaryStage;
loadMainWindow();
}
public void loadMainWindow() throws IOException {
FXMLLoader loaderMainWindow = new FXMLLoader(Main.class.getResource("MainWindow.fxml"));
mainWindow = loaderMainWindow.load();
FXMLLoader loaderLeft = new FXMLLoader(Main.class.getResource("Left.fxml"));
left = loaderLeft.load();
mainWindow.setLeft(left);
//mainWindow.setBottom(bottom);
Scene scene = new Scene(mainWindow);
rootStage.setScene(scene);
rootStage.show();
}
public void main(String[] args) {
launch(args);
}
}
MainWindow.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.MainWindowController" />
MainWindowController:
package sample;
import javafx.fxml.Initializable;
import java.net.URL;
import java.util.ResourceBundle;
public class MainWindowController implements Initializable {
private Main main;
#Override
public void initialize(URL url, ResourceBundle resourceBundle) {
}
public void setMain(Main main) {
this.main = main;
}
}
Left.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="400.0" prefWidth="100.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.LeftController">
<children>
<Button fx:id="button" layoutX="237.0" layoutY="169.0" mnemonicParsing="false" onAction="#buttonClick" text="Button" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>
LeftController.java:
package sample;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import java.awt.event.ActionEvent;
import java.net.URL;
import java.util.ResourceBundle;
public class LeftController implements Initializable {
#FXML
private Button button;
#Override
public void initialize(URL url, ResourceBundle resourceBundle) {
}
public void buttonClick(javafx.event.ActionEvent actionEvent) {
System.out.println("Some Stuff");
}
}
Solution
The error you're getting is caused by your main(String[]) method not being static. If you make it static then the error will go away.
Some Explanation
JavaFX offers the ability to launch applications without providing a main method, so long as the main class is a subclass of Application. However, developers can still include a main method which means this special launch functionality has to handle that situation gracefully. In other words, an explicit main method present in the Application subclass must act like the entry point of the application from the developer's point of view. Nonetheless, behind the scenes some deep internal class has become the "real" main class.
To do this, the main method is located—if present at all—via Class#getMethod(String,Class...) which, while only returning public methods, doesn't distinguish between static and non-static methods. If found, Method#invoke(Object,Object...) is used to invoke the main method reflectively. The first argument of invoke is the instance that the method should be invoked on; in the case of static methods the value is null. Unfortunately, the code assumes the method it found is static which causes a NullPointerException to be thrown—you can't call an instance method on a null "instance".
Update: This issue has been submitted on GitHub (#570) and subsequently JBS (JDK-8230119). The current idea is to emit a warning rather than throw the NullPointerException. However, the functionality that allows launching without a main method may be deprecated in a future release, which will affect how this issue is addressed.

How to solve JavaFX problem for using pop-up notifications

I am learning JavaFX and my IDE for doing that is NetBeans IDE 8.2.
I have a problem when I want to run a project.
my sample project is Drag and Drop a picture on ImageView by scene builder.
the error is:
Executing C:\Users\Mohammad Sadeghi\Documents\NetBeansProjects\DragDrop\dist\run1057050476\DragDrop.jar using platform C:\Program Files\Java\jdk1.8.0_212\jre/bin/java
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$159(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassCastException: javafx.scene.image.ImageView cannot be cast to javafx.scene.Parent
at dragdrop.DragDrop.start(DragDrop.java:22)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$166(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$179(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$177(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$178(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$152(WinApplication.java:177)
... 1 more
Exception running application dragdrop.DragDrop
Java Result: 1
my FXMLDocument.fxml is :
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.image.ImageView?>
<ImageView fx:id="ImgID" fitHeight="228.0" fitWidth="248.0" onDragDone="#ondragdone" pickOnBounds="true" preserveRatio="true" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="dragdrop.FXMLDocumentController"/>
FXMLDocumentController.java :
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package drag-drop;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.DragEvent;
/**
*
* #author Mohammad Sadeghi
*/
public class FXMLDocumentController implements Initializable {
private Label label;
#FXML
private ImageView ImgID;
public FXMLDocumentController() {
}
private void handleButtonAction(ActionEvent event) {
System.out.println("You clicked me!");
label.setText("Hello World!");
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
#FXML
private void ondragdone(DragEvent event) {
List<File> fi=event.getDragboard().getFiles();
try {
Image img=new Image(new FileInputStream(fi.get(0)));
ImgID.setImage(img);
} catch (Exception e) {
System.out.println("ERROR");
}
}
}
and my Main app() is :
public class DragDrop extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I don't know what is this error for !!
I have almost the same error on another JavaFX project when I am using of Scenebuilder.
could anyone help me?
If you look at the signature of FXMLLoader#load(URL) you'll see:
public static <T> T load​(URL location) throws IOException
Notice the <T>? That makes the method generic and the type parameter is used as the return type of the method. This is what allows you to assign the result of calling #load(URL) to a variable of any type, such as you're doing.
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
You could literally change the type of root to any other type and the code would still compile. Currently, however, the above code has T being inferred as Parent. Under the hood this uses a cast, same as you would have to do if the #load(URL) method returned Object instead of T.
Parent root = (Parent) FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
The problem is your FXML declares the root element to be an ImageView. This means the actual type of object being returned by the #load(URL) method is ImageView, not Parent, and the ImageView class is not a subtype of Parent—thus the ClassCastException.
One option is to use ImageView root = ...;. However, this is not sufficient because you are attempting to use root as the root of a Scene which must be a Parent. The better solution is to wrap ImageView in a Parent in the FXML file. Here's an example using a StackPane:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.StackPane?>
<StackPane xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="dragdrop.FXMLDocumentController">
<ImageView fx:id="ImgID" fitHeight="228.0" fitWidth="248.0" onDragDone="#ondragdone"
pickOnBounds="true" preserveRatio="true"/>
</StackPane>

Making stages a separate class and making unique methods for them

I have a class called MainStage that extends to the stage class of javafx.
This is part of that class.
public void changeScene(){
if(onLogin)
setScene(mainScene);
else{
setScene(loginScene);
onLogin = false;
}
}
I use this method inside of the MainStage class to change scenes. I call the MainStage inside of the controller for the Scene
public class loginSceneController{
#FXML
private Button submit;
#FXML
private TextField usernameField;
#FXML
private PasswordField passwordField;
MainStage stage = (MainStage) submit.getScene().getWindow(); //This is where the nullpointer is thrown
public void handle() {
submit.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
stage.changeScene();
System.out.println("Stage changed sucessfully!!");
}
});
}
}
When I try to run it, it throws this:
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException: /C:/Users/Max/workspace/CloudCCP/target/classes/Window/LoginScene.fxml:9
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at Window.MainStage.<init>(MainStage.java:24)
at Window.Window.start(Window.java:28)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
... 1 more
Caused by: java.lang.NullPointerException
at Window.loginSceneController.<init>(loginSceneController.java:30)
The MainStage stage line needs to be moved inside your event handler.
Currently, it is a declaration which is not in any method, so it is considered a field of the class. Which means it runs before the loginSceneController instance is created and available to other code. Since no other code can see the object yet, all other fields (including submit) are still null.
Furthermore, you can’t very well access the button’s Scene if the button hasn’t been added to a Scene yet. It’s probably safe to assume that if the user managed to trigger the submit Button’s action, the button must be in a Scene in a visible Window, so the event handler is the ideal place accessing the parent Scene and Window.
Since you asked about execution order: Any time an object is created with new, the object must first run all of its initializers, in the order they appear in the code, and then the invoked constructor. Until that happens, the object isn’t actually created and no other code can use it or refer to it,* including the FXMLLoader. All fields are initially null, zero, or false, unless they are initialized (like private int x = 4;).
Until your object is fully constructed, none of the #FXML-annotated fields will be non-null.
* Technically, it is possible for a constructor to “leak” a reference to the new object before the constructor is complete, but it’s considered bad practice to do so.

Java LibGDX Texture gives null pointer exception

I've been using LibGDX for a project and whenever i declare a Texture it gives :
Exception in thread "main" java.lang.NullPointerException
at com.fistbump.patman.test.main(test.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140
The code is :
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
public class test {
public static void main(String[] args){
Texture text = new Texture(Gdx.files.internal("Path.png"));
OR
Texture text = new Texture("Path.png");
}
}
I am really stuck here . Thanks in advance
You cant use (the majority of) libGDX before it is initialized. This is in or after the create method of your ApplicationListener (or ApplicationAdapter or Game if your prefer).
See also: https://github.com/libgdx/libgdx/wiki/The-life-cycle

Java FX Exception (Media Player Application)

I'm just starting to use Java FX and cannot for the life of me figure out why this exception keeps occurring.
I have 2 classes. One called Main and the other called Player. Here is what they each look like....
Main Class
package application;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
Player player = new Player("/Applications/Nacho.mp4");
Scene scene = new Scene (player, 720, 480, Color.BLACK);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Player Class
package application;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
public class Player extends BorderPane {
Media media;
MediaPlayer player;
MediaView view;
Pane nPane;
public Player(String file){
media = new Media(file);
player = new MediaPlayer(media);
view = new MediaView(player);
nPane = new Pane();
nPane.getChildren().add(view);
setCenter(nPane);
player.play();
}
}
Here is what the compiler spits out when I run the program...
START
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(LauncherImpl.java:182)
at com.sun.javafx.application.LauncherImpl$$Lambda$51/1323468230.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: uri.getScheme() == null! uri == 'Applications/Nacho.mp4'
at com.sun.media.jfxmedia.locator.Locator.(Locator.java:211)
at javafx.scene.media.Media.(Media.java:391)
at application.Player.(Player.java:16)
at application.Main.start(Main.java:13)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
at com.sun.javafx.application.LauncherImpl$$Lambda$54/1046396900.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/186276003.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$49/287662571.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/237061348.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Exception running application application.Main
FINISH
I know that the issue occurs as soon as the Player object is instantiated in Main. As soon the Player object uses it's constructor and creates a Media object, which gets passed the String file location, that's when I get the error. I ran the program with an empty constructor for the Player object and it ran fine so the issue is clearly in my Player Class, again when the Media object is instantiated. Am I passing the correct parameters? "/Applications/Nacho.mp4"
If someone can please tell me how to fix this, I would greatly appreciate it. I literally can't move forward with this project otherwise. Thank you!
Nevermind, I figured it out, the problem was passing the parameter to the Media object. I'm used to C++ syntax and did not realize that the proper way to do it is
media = new Media("file:///Applications/Nacho.mp4");
This error usually occurs due to wrongly input of the file address. The correct way to write the address is file:///C:/abc.mp4.
More clearly:
Object b = new Object("file:///C:/abc.mp4");

Categories