0

I'm working on a school project and trying to launch the GUI for a playlist. A groupmate of mine has also introduced Maven components to the project itself so we can upload, get values from, and play audio like an actual playlist.

However, when I uploaded her file with the Maven components, the GUI refuses to launch saying that

The method launch(String[]) is undefined for the type application

I expected to have the GUI pop up on my screen but I get the error of

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    The method launch(String[]) is undefined for the type application
    at playlistProject/playlist.application.main(application.java:157) 

Below is the code and I'm wondering if it is an issue with the code or another property with JavaFX or Maven.

package playlist;

import java.io.File;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.collections.ObservableList;
import javafx.collections.FXCollections;
import javafx.scene.control.cell.ComboBoxListCell;
import javafx.scene.layout.StackPane;
import javafx.scene.control.Button;
import playlist.*;
import playlist.Playlist;
import javafx.stage.FileChooser;
import javafx.scene.control.ListView;

public class application {
    
    private ListView<String> allSongs = new ListView<>();
    //public ObservableList test = FXCollections.observableArrayList();
    private TextField txtSongName = new TextField();
    private TextField txtSongArtist = new TextField();
    private TextField txtGenre = new TextField();
    
    public void start(Stage primaryStage) {
        try {
            GridPane root = new GridPane();
            root.setPadding(new Insets(20));
            root.setHgap(15);
            root.setVgap(15);
            Scene scene = new Scene(root,700,600);
            root.add(search(), 0, 0);
            root.add(searchBoxes(), 0, 1);
            FileChooser fileChooser = new FileChooser();
            Button button = new Button("Click to add song files");
            EventHandler<ActionEvent> event  = new EventHandler<ActionEvent>() {
                public void handle(ActionEvent e) {
                    File file = fileChooser.showOpenDialog(primaryStage);
                }
            };
            button.setOnAction(event);
            root.add(button, 0, 2);
            root.add(listViewSongs(), 0, 3);
            root.add(additionalButtons(), 0, 4);

            listViewSongs();
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.setTitle("Playlist");
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
    
    private Pane search() {
        HBox row = new HBox();
        Label label = new Label("Search song by:");
        row.getChildren().add(label);
        return row;
    }
    
    private Pane searchBoxes() {
        HBox row = new HBox();
        Label song = new Label("Song Name: ");
        txtSongName.setPrefWidth(150);
        Label artist = new Label(" Artist: ");
        txtSongArtist.setPrefWidth(150);
        Label genre = new Label(" Genre: ");
        txtGenre.setPrefWidth(150);
        row.getChildren().addAll(song, txtSongName, artist, txtSongArtist, genre, txtGenre);
        return row;
    }
    
    private Pane listViewSongs() {
        VBox column = new VBox();
        Label label = new Label("Playlist");
        allSongs.setPrefHeight(100);
        column.getChildren().addAll(label, allSongs);
        return column;
    }
    
    private Pane additionalButtons() {
        GridPane grid = new GridPane();
        grid.setHgap(10);
        grid.setVgap(10);
        Button btnPlayPause = new Button("Play/Pause");
        btnPlayPause.setOnAction(new handlePlayPause());
        Button btnSkip = new Button("Skip");
        btnSkip.setOnAction(new handleSkip());
        Button btnShuffle = new Button("Shuffle");
        btnShuffle.setOnAction(new handleShuffle());
        Button btnRemove = new Button("Remove Song");
        btnRemove.setOnAction(new handleRemove());
        
        grid.add(btnPlayPause, 0, 4);
        grid.add(btnSkip, 1, 4);
        grid.add(btnShuffle, 2, 4);
        grid.add(btnRemove, 3, 4);
        return grid;
    }
    
    public class handlePlayPause implements EventHandler<ActionEvent> {

        @Override
        public void handle(ActionEvent arg0) {
            // TODO Auto-generated method stub
            
        }
        
    }
    
    public class handleSkip implements EventHandler<ActionEvent> {

        @Override
        public void handle(ActionEvent arg0) {
            // TODO Auto-generated method stub
        }
        
    }
    
    public class handleShuffle implements EventHandler<ActionEvent> {

        @Override
        public void handle(ActionEvent arg0) {
            // TODO Auto-generated method stub
        }
    }
    
    public class handleRemove implements EventHandler<ActionEvent> {

        @Override
        public void handle(ActionEvent arg0) {
            // TODO Auto-generated method stub
        }
        
    }
    
    public static void main(String[] args) {
        launch(args);
    }
}
5
  • 6
    Your class needs to extend javafx.application.Application. I also recommend you change your class's name to something other than application (not to Application). Commented Apr 22 at 0:00
  • 2
    I edited your tags to remove compiler-error, this is a runtime error not a compilation error. Commented Apr 22 at 2:22
  • 3
    Class names in Java begin with an uppercase letter. Commented Apr 22 at 6:45
  • 2
    Consider using public class Playlist extends Application and renaming your source file to Playlist.java. Commented Apr 22 at 15:02
  • docs.oracle.com/javase/8/javafx/get-started-tutorial/… Commented Apr 22 at 16:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.