Error: Could not find or load main class studiplayer.ui.Player
Caused by: java.lang.ClassNotFoundException: studiplayer.ui.Player
[CODE lang="java" title="player"]package studiplayer.ui;
//Imports -> Jede Menge wegen JavaFX
import java.net.URL;
import java.util.List;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import studiplayer.audio.AudioFile;
import studiplayer.audio.NotPlayableException;
import studiplayer.audio.PlayList;
public class Player extends Application{
private volatile boolean editorVisible;
private Button prevButton;
private Button playButton;
private Button pauseButton;
private Button stopButton;
private Button nextButton;
private Button editorButton;
private PlayList playList;
public static final String DEFAULT_PLAYLIST = "playlists/DefaultPlayList.m3u";
private String playListPathname;
private final String initialPosition = "00:00";
private final String currentSongString = "Current song: ";
private final String noCurrentSong = "no current song";
private boolean stopped;
private Label songDescription;
private Label playTime;
private Stage primaryStage;
private PlayListEditor playListEditor;
public Player() {
}
@Override
public void start(Stage primaryStage) throws Exception {
this.primaryStage = primaryStage;
BorderPane mainPane = new BorderPane();
//Aus den Parametern den Pfad der Playlist heraussuchen (get) und Playlist laden
List<String> parameters = getParameters().getRaw();
playList = new PlayList();
if(!parameters.isEmpty()) playListPathname = parameters.get(0);
else playListPathname = DEFAULT_PLAYLIST;
playList.loadFromM3U(playListPathname);
//PlayListEditor erstellen und Visible = true
playListEditor = new PlayListEditor(this, this.playList);
editorVisible = false;
songDescription = new Label();
songDescription.setPadding(new Insets(5,10,5,6));
//Das Label für die Abspielanzeige erstellen und mit Insets "positionieren"
playTime = new Label("--:--");
playTime.setPadding(new Insets(18,10,10,10));
//Buttons erstellen und den Event-Handler zuordnen
//Funktionierender prev-Button (bei APA auskommentiert weiß nicht ob er ihn haben will oder nicht)
prevButton = createButton("previous.png");
prevButton.setOnAction (e -> {
prevSong();
});
playButton = createButton("play.png");
playButton.setOnAction(e -> {
playCurrentSong();
});
pauseButton = createButton("pause.png");
pauseButton.setOnAction(e-> {
pauseCurrentSong();
});
stopButton = createButton("stop.png");
stopButton.setOnAction(e-> {
stopCurrentSong();
});
nextButton = createButton("next.png");
nextButton.setOnAction(e-> {
nextSong();
});
editorButton = createButton("pl_editor.png");
editorButton.setOnAction(e -> {
if(editorVisible)
{
editorVisible = false;
playListEditor.hide();
}
else
{
editorVisible = true;
playListEditor.show();
}
});
//Die Buttons der HBox zuordnen
HBox center = new HBox();
center.getChildren().add(playTime);
center.getChildren().add(prevButton);
center.getChildren().add(playButton);
center.getChildren().add(pauseButton);
center.getChildren().add(stopButton);
center.getChildren().add(nextButton);
center.getChildren().add(editorButton);
//Die aktuellen Song-Infos ausgeben, egal ob in der Playlist ein Lied ist oder nicht
if (playList != null && playList.size() > 0) {
updateSongInfo(playList.getCurrentAudioFile());
} else {
updateSongInfo(null);
}
//Erstmal keinen Song abspielen, deshalb stopped=true!
stopped = true;
//ButtonStates setzen am Anfang gleich
setButtonStates(false, true, false, true, false, false);
mainPane.setTop(songDescription);
mainPane.setCenter(center);
Scene scene = new Scene(mainPane, 700, 90); //Scene erstellen
primaryStage.setOnCloseRequest(e -> {
if (!stopped) stopCurrentSong();
});
primaryStage.setScene(scene);; //Stage zuordnen
primaryStage.show(); //Stage anzeigen
}
private Button createButton(String iconfile) {
Button button = null;
try {
URL url = getClass().getResource("/icons/" + iconfile);
Image icon = new Image(url.toString());
ImageView imageview = new ImageView(icon);
imageview.setFitHeight(48);
imageview.setFitWidth(48);
button = new Button("", imageview);
button.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
} catch (Exception e){
System.out.println("Image " + "icons/" + iconfile + " not found!");
System.exit(-1);
}
return button;
}
public void setEditorVisible(boolean pEditorVisible) {
editorVisible = pEditorVisible;
}
//Setter und Getter für die playList:
public String getPlayListPathname() {
return playList.getCurrentAudioFile().getFilename();
}
public void setPlayList(String playListPath) {
if (playListPath != null) {
playListPathname = playListPath;
playList.loadFromM3U(playListPath);
Platform.runLater(() -> updateSongInfo(playList.getCurrentAudioFile()));
} else {
playList.clear();
playList.loadFromM3U(DEFAULT_PLAYLIST);
playList.clear();
}
}
//Die Methoden für die Event-Handler der Buttons:
public void playCurrentSong() { //Für den Start/Play Knopf im EventHandling
// Holt Song aus der PlayList raus und spielt ihn ab
// stoppen, falls grad ein Lied läuft
if(!stopped) stopCurrentSong();
//Dann wird was abgespielt
stopped = false;
//System.out.println("Playing " + playlist.getCurrentAudioFile().toString());
if(playList!= null && playList.size()>0) {
updateSongInfo(playList.getCurrentAudioFile());
setButtonStates(true, false, false, false, false, false);
}
else {
updateSongInfo(null); //GUI updaten
setButtonStates(true, true, true, true, false, true);
}
//Timer-Thread und Player-Thread starten mit der start()-Methode
if(!playList.isEmpty()) {
(new TimerThread()).start();
(new PlayerThread()).start();
}
}
public void pauseCurrentSong() { // Für Pause Knopf im EventHandler
//Wenn man pausiert... Lied anhalten -> togglePause aufrufen
if(!playList.isEmpty() && playList.getCurrentAudioFile()!=null) {
playList.getCurrentAudioFile().togglePause();
}
//System.out.println("Pause + playlist.getCurrentAudioFile().toString()");
setButtonStates(true, false, false, false, false, false);
}
public void stopCurrentSong() {
stopped = true;
//System.out.println("Stop + playlist.getCurrentAudioFile().toString()");
if(playList != null && playList.size()>0) {
playList.getCurrentAudioFile().stop();
updateSongInfo(playList.getCurrentAudioFile()); //GUI updaten
setButtonStates(false, true, false, true, false, false);
}
else {
updateSongInfo(null);
setButtonStates(true, true, true, true, false, true);
}
}
public void nextSong() { //Vielleicht auch oben reinkopieren in EventHandler...
if (playList != null && !playList.isEmpty()) {
stopCurrentSong();
playList.changeCurrent();
playCurrentSong();
}
}
//Needed fuer prevButton:
public void prevSong() {
if(playList != null && !playList.isEmpty()) {
stopCurrentSong();
int aktIndex = playList.getCurrent();
if(aktIndex!=0) aktIndex--;
else aktIndex = playList.size()-1;
playList.setCurrent(aktIndex);
playCurrentSong();
}
}
//GUI-updaten-Methoden:
private void updateSongInfo(AudioFile af) { //für Kopfzeile
if(af == null) {
songDescription.setText(noCurrentSong);
primaryStage.setTitle(noCurrentSong);
playTime.setText("--:--");
}
else {
songDescription.setText(af.toString());
primaryStage.setTitle(currentSongString + af.toString());
playTime.setText(af.getFormattedPosition());
}
}
public void refreshUI() {
Platform.runLater(() -> {
if (playList != null && playList.size() > 0) {
updateSongInfo(playList.getCurrentAudioFile());
} else {
updateSongInfo(null);
setButtonStates(true, true, true, true, false, true);
}
});
}
private void setButtonStates(boolean playButtonState, boolean stopButtonState,
boolean nextButtonState, boolean pauseButtonState, boolean editorButtonState ,
boolean prevButtonState) {
playButton.setDisable(playButtonState);
stopButton.setDisable(stopButtonState);
nextButton.setDisable(nextButtonState);
pauseButton.setDisable(pauseButtonState);
editorButton.setDisable(editorButtonState);
prevButton.setDisable(prevButtonState);
}
//inner classes:
private class TimerThread extends Thread { //Ändern der Sekunden im Label
public void run() {
//Alle 100ms ändern
while(!stopped && !playList.isEmpty()) {
Platform.runLater(() ->
playTime.setText(playList.getCurrentAudioFile().getFormattedPosition())
); //Label
try {
sleep(100);
} catch (InterruptedException e) { }
}
Platform.runLater(()-> playTime.setText(initialPosition));
}
}
private class PlayerThread extends Thread {
public void run() {
while(!playList.isEmpty() && !stopped) {
try {
playList.getCurrentAudioFile().play();
} catch (NotPlayableException e) {
e.printStackTrace();
}
}
//Weiterhin !stopped:
if(!stopped) {
playList.changeCurrent();
updateSongInfo(playList.getCurrentAudioFile());
}
}
}
//Main
public static void main(String[] args) {
launch(args);
}
}[/CODE]
einer vielleicht eine Idee, was der Fehler sein könnte?
Caused by: java.lang.ClassNotFoundException: studiplayer.ui.Player
[CODE lang="java" title="player"]package studiplayer.ui;
//Imports -> Jede Menge wegen JavaFX
import java.net.URL;
import java.util.List;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import studiplayer.audio.AudioFile;
import studiplayer.audio.NotPlayableException;
import studiplayer.audio.PlayList;
public class Player extends Application{
private volatile boolean editorVisible;
private Button prevButton;
private Button playButton;
private Button pauseButton;
private Button stopButton;
private Button nextButton;
private Button editorButton;
private PlayList playList;
public static final String DEFAULT_PLAYLIST = "playlists/DefaultPlayList.m3u";
private String playListPathname;
private final String initialPosition = "00:00";
private final String currentSongString = "Current song: ";
private final String noCurrentSong = "no current song";
private boolean stopped;
private Label songDescription;
private Label playTime;
private Stage primaryStage;
private PlayListEditor playListEditor;
public Player() {
}
@Override
public void start(Stage primaryStage) throws Exception {
this.primaryStage = primaryStage;
BorderPane mainPane = new BorderPane();
//Aus den Parametern den Pfad der Playlist heraussuchen (get) und Playlist laden
List<String> parameters = getParameters().getRaw();
playList = new PlayList();
if(!parameters.isEmpty()) playListPathname = parameters.get(0);
else playListPathname = DEFAULT_PLAYLIST;
playList.loadFromM3U(playListPathname);
//PlayListEditor erstellen und Visible = true
playListEditor = new PlayListEditor(this, this.playList);
editorVisible = false;
songDescription = new Label();
songDescription.setPadding(new Insets(5,10,5,6));
//Das Label für die Abspielanzeige erstellen und mit Insets "positionieren"
playTime = new Label("--:--");
playTime.setPadding(new Insets(18,10,10,10));
//Buttons erstellen und den Event-Handler zuordnen
//Funktionierender prev-Button (bei APA auskommentiert weiß nicht ob er ihn haben will oder nicht)
prevButton = createButton("previous.png");
prevButton.setOnAction (e -> {
prevSong();
});
playButton = createButton("play.png");
playButton.setOnAction(e -> {
playCurrentSong();
});
pauseButton = createButton("pause.png");
pauseButton.setOnAction(e-> {
pauseCurrentSong();
});
stopButton = createButton("stop.png");
stopButton.setOnAction(e-> {
stopCurrentSong();
});
nextButton = createButton("next.png");
nextButton.setOnAction(e-> {
nextSong();
});
editorButton = createButton("pl_editor.png");
editorButton.setOnAction(e -> {
if(editorVisible)
{
editorVisible = false;
playListEditor.hide();
}
else
{
editorVisible = true;
playListEditor.show();
}
});
//Die Buttons der HBox zuordnen
HBox center = new HBox();
center.getChildren().add(playTime);
center.getChildren().add(prevButton);
center.getChildren().add(playButton);
center.getChildren().add(pauseButton);
center.getChildren().add(stopButton);
center.getChildren().add(nextButton);
center.getChildren().add(editorButton);
//Die aktuellen Song-Infos ausgeben, egal ob in der Playlist ein Lied ist oder nicht
if (playList != null && playList.size() > 0) {
updateSongInfo(playList.getCurrentAudioFile());
} else {
updateSongInfo(null);
}
//Erstmal keinen Song abspielen, deshalb stopped=true!
stopped = true;
//ButtonStates setzen am Anfang gleich
setButtonStates(false, true, false, true, false, false);
mainPane.setTop(songDescription);
mainPane.setCenter(center);
Scene scene = new Scene(mainPane, 700, 90); //Scene erstellen
primaryStage.setOnCloseRequest(e -> {
if (!stopped) stopCurrentSong();
});
primaryStage.setScene(scene);; //Stage zuordnen
primaryStage.show(); //Stage anzeigen
}
private Button createButton(String iconfile) {
Button button = null;
try {
URL url = getClass().getResource("/icons/" + iconfile);
Image icon = new Image(url.toString());
ImageView imageview = new ImageView(icon);
imageview.setFitHeight(48);
imageview.setFitWidth(48);
button = new Button("", imageview);
button.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
} catch (Exception e){
System.out.println("Image " + "icons/" + iconfile + " not found!");
System.exit(-1);
}
return button;
}
public void setEditorVisible(boolean pEditorVisible) {
editorVisible = pEditorVisible;
}
//Setter und Getter für die playList:
public String getPlayListPathname() {
return playList.getCurrentAudioFile().getFilename();
}
public void setPlayList(String playListPath) {
if (playListPath != null) {
playListPathname = playListPath;
playList.loadFromM3U(playListPath);
Platform.runLater(() -> updateSongInfo(playList.getCurrentAudioFile()));
} else {
playList.clear();
playList.loadFromM3U(DEFAULT_PLAYLIST);
playList.clear();
}
}
//Die Methoden für die Event-Handler der Buttons:
public void playCurrentSong() { //Für den Start/Play Knopf im EventHandling
// Holt Song aus der PlayList raus und spielt ihn ab
// stoppen, falls grad ein Lied läuft
if(!stopped) stopCurrentSong();
//Dann wird was abgespielt
stopped = false;
//System.out.println("Playing " + playlist.getCurrentAudioFile().toString());
if(playList!= null && playList.size()>0) {
updateSongInfo(playList.getCurrentAudioFile());
setButtonStates(true, false, false, false, false, false);
}
else {
updateSongInfo(null); //GUI updaten
setButtonStates(true, true, true, true, false, true);
}
//Timer-Thread und Player-Thread starten mit der start()-Methode
if(!playList.isEmpty()) {
(new TimerThread()).start();
(new PlayerThread()).start();
}
}
public void pauseCurrentSong() { // Für Pause Knopf im EventHandler
//Wenn man pausiert... Lied anhalten -> togglePause aufrufen
if(!playList.isEmpty() && playList.getCurrentAudioFile()!=null) {
playList.getCurrentAudioFile().togglePause();
}
//System.out.println("Pause + playlist.getCurrentAudioFile().toString()");
setButtonStates(true, false, false, false, false, false);
}
public void stopCurrentSong() {
stopped = true;
//System.out.println("Stop + playlist.getCurrentAudioFile().toString()");
if(playList != null && playList.size()>0) {
playList.getCurrentAudioFile().stop();
updateSongInfo(playList.getCurrentAudioFile()); //GUI updaten
setButtonStates(false, true, false, true, false, false);
}
else {
updateSongInfo(null);
setButtonStates(true, true, true, true, false, true);
}
}
public void nextSong() { //Vielleicht auch oben reinkopieren in EventHandler...
if (playList != null && !playList.isEmpty()) {
stopCurrentSong();
playList.changeCurrent();
playCurrentSong();
}
}
//Needed fuer prevButton:
public void prevSong() {
if(playList != null && !playList.isEmpty()) {
stopCurrentSong();
int aktIndex = playList.getCurrent();
if(aktIndex!=0) aktIndex--;
else aktIndex = playList.size()-1;
playList.setCurrent(aktIndex);
playCurrentSong();
}
}
//GUI-updaten-Methoden:
private void updateSongInfo(AudioFile af) { //für Kopfzeile
if(af == null) {
songDescription.setText(noCurrentSong);
primaryStage.setTitle(noCurrentSong);
playTime.setText("--:--");
}
else {
songDescription.setText(af.toString());
primaryStage.setTitle(currentSongString + af.toString());
playTime.setText(af.getFormattedPosition());
}
}
public void refreshUI() {
Platform.runLater(() -> {
if (playList != null && playList.size() > 0) {
updateSongInfo(playList.getCurrentAudioFile());
} else {
updateSongInfo(null);
setButtonStates(true, true, true, true, false, true);
}
});
}
private void setButtonStates(boolean playButtonState, boolean stopButtonState,
boolean nextButtonState, boolean pauseButtonState, boolean editorButtonState ,
boolean prevButtonState) {
playButton.setDisable(playButtonState);
stopButton.setDisable(stopButtonState);
nextButton.setDisable(nextButtonState);
pauseButton.setDisable(pauseButtonState);
editorButton.setDisable(editorButtonState);
prevButton.setDisable(prevButtonState);
}
//inner classes:
private class TimerThread extends Thread { //Ändern der Sekunden im Label
public void run() {
//Alle 100ms ändern
while(!stopped && !playList.isEmpty()) {
Platform.runLater(() ->
playTime.setText(playList.getCurrentAudioFile().getFormattedPosition())
); //Label
try {
sleep(100);
} catch (InterruptedException e) { }
}
Platform.runLater(()-> playTime.setText(initialPosition));
}
}
private class PlayerThread extends Thread {
public void run() {
while(!playList.isEmpty() && !stopped) {
try {
playList.getCurrentAudioFile().play();
} catch (NotPlayableException e) {
e.printStackTrace();
}
}
//Weiterhin !stopped:
if(!stopped) {
playList.changeCurrent();
updateSongInfo(playList.getCurrentAudioFile());
}
}
}
//Main
public static void main(String[] args) {
launch(args);
}
}[/CODE]
einer vielleicht eine Idee, was der Fehler sein könnte?