0

I need a parameter for the setRedirectUri method but it only takes URI. Is there a way to convert String into URI?

import com.wrapper.spotify.*;
import java.net.URI;

public class Music {

    private String id;
    private String secret;

    public void authenticate(String id, String secret)
    {
        this.id = id;
        this.secret = secret;
        URI myAccount = new URI("<URI>");
        SpotifyApi spotifyApi = new SpotifyApi.Builder()
                .setClientId(this.id)
                .setClientSecret(this.secret)
                .setRedirectUri(myAccount)
                .build();
    }
}
NovaG35
  • 3
  • 1
  • `java.net.URI` has a constructor which accepts just a String. `new URI(myString);` – Liftoff Mar 19 '21 at 19:09
  • 1
    Does this answer your question? [Convert String to Uri](https://stackoverflow.com/questions/3487389/convert-string-to-uri) – Vimukthi Mar 19 '21 at 19:33
  • i've tried that and the constructor gives this error "Unhandled exception type URISyntaxException" am i missing some syntax? – NovaG35 Mar 19 '21 at 19:42
  • @NovaG35 Well, try to wrap those lines with a try catch block or add throws URISyntaxException to your method – Vimukthi Mar 19 '21 at 19:58

1 Answers1

0

Try this out:

        SpotifyApi spotifyApi = new SpotifyApi.Builder()
                .setClientId(this.id)
                .setClientSecret(this.secret)
                .setRedirectUri(
                     new java.net.URI("<your URI>"))
                .build();

https://docs.oracle.com/javase/8/docs/api/java/net/URI.html?is-external=true

Mickey Tin
  • 3,408
  • 10
  • 42
  • 71