From 8acace8c198a81d89a3cd8c4846dbe0c0d76463d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Thu, 28 Jun 2012 20:12:36 +0200 Subject: [PATCH] fixed mpd nullpointer exceptions --- src/de/ctdo/crashtest/mpd/MPDController.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/de/ctdo/crashtest/mpd/MPDController.java b/src/de/ctdo/crashtest/mpd/MPDController.java index 42728fc..614e2ee 100644 --- a/src/de/ctdo/crashtest/mpd/MPDController.java +++ b/src/de/ctdo/crashtest/mpd/MPDController.java @@ -48,7 +48,7 @@ public class MPDController implements IMPDController { @Override public void run() { synchronized (mpd) { - addToPlayListIfNeeded(artist, title); + doPlaySong(artist,title); } @@ -68,6 +68,8 @@ public class MPDController implements IMPDController { int tries = 3; while(tries>0) { + addToPlayListIfNeeded(artist, title); + for(MPDSong song: playlist.getSongList()) { if(checkSong(song, artist, title)) { System.out.println("MPD: stopping, playing, go..."); @@ -85,7 +87,7 @@ public class MPDController implements IMPDController { System.out.println("MPD: song is correctly playing"); return; } else { - System.out.println("MPD: wrong track is playing. " + song.getArtist() + " - " + song.getTitle()); + System.out.println("MPD: wrong track is playing"); } System.out.println("MPD: next try"); @@ -102,10 +104,14 @@ public class MPDController implements IMPDController { } private boolean checkSong(final MPDSong song, final String artist, final String title) { - if(song.getArtist() != null && song.getTitle() != null) { - if(song.getArtist().getName().toLowerCase().contentEquals(artist.toLowerCase()) && - song.getTitle().toLowerCase().contentEquals(title.toLowerCase())) { - return true; + if(song != null) { + if(song.getArtist() != null && song.getTitle() != null) { + if(song.getArtist().getName().toLowerCase().contentEquals(artist.toLowerCase()) && + song.getTitle().toLowerCase().contentEquals(title.toLowerCase())) { + return true; + } + } else { + System.out.println("MPD: song is nullb"); } } else { System.out.println("MPD: track title or artist is null " + artist + " - " + title);