Skip to content
This repository has been archived by the owner on Aug 31, 2020. It is now read-only.

Commit

Permalink
Add: default path, Fix: nullpointer exception
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonjanas committed May 5, 2020
1 parent b197b1f commit 9439e5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/janas/PiRadio/API/RadioAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ public String validate(){
@GetMapping("/on/{name}")
public void turnOnRadio(@PathVariable("name") String name ){
try {
Radio.init(radioStations.getStation(name));
String path = radioStations.getStation(name);
if (path.length() > 0){
Radio.init(path);
}
} catch (Exception e){
System.out.println("Exception: " + e.toString());
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/janas/PiRadio/Radio/RadioStations.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ public class RadioStations {

private Map<String, String> stations = new HashMap<>();

private File file = new File("radio-stations.txt");
private File file;

public RadioStations(){
String path = "/home/" + System.getProperty("user.name") + "/radio-stations.txt";
file = new File(path);
load();
}

public String getStation(String name){
return stations.get(name);
if (stations.containsKey(name)){
return stations.get(name);
}
return "";
}

public void putStation(String name, String url){
Expand Down

0 comments on commit 9439e5c

Please sign in to comment.