I have a method that returns 5 Strings of URLs. It then puts the URLs into string variables for the event handler buttons to open the URL.
I get the error:
Illegal character in query at index 67.
If I put the actual string URL, the button opens it:
"https://www.youtube.com/watch?v=-BPMacaIwqg&ab_channel=DryBarComedy,"
From my understanding, if the string variable contains the same string, it should open the link but it doesn't. Why?
public void returnVideoUrls() throws IOException {
UIController returnedFormats = new UIController();
// returns list of urls
// stores urls into an arraylist
ArrayList<String> formattedCode = returnedFormats.combineVideosUrl(videoText.getText());
//puts each url into a string
String yes1 = formattedCode.get(0);
String yes2 = formattedCode.get(1);
String yes3 = formattedCode.get(2);
String yes4 = formattedCode.get(3);
String yes5 = formattedCode.get(4);
//each event handler opens the link
videoButton1.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event){
try {
Desktop.getDesktop().browse(new URI(yes1));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
});
videoButton2.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event){
try {
Desktop.getDesktop().browse(new URI(yes2));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
});
videoButton3.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event){
try {
Desktop.getDesktop().browse(new URI(yes3));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
});
videoButton4.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event){
try {
Desktop.getDesktop().browse(new URI(yes4));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
});
videoButton5.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event){
try {
Desktop.getDesktop().browse(new URI(yes5));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
});
}