Import java.net.URI doesn't work

I am going to make a URI using java.net.URI, it gives me the following error Unhandled exception type URISyntaxException, Im wondering why (import java.net.URI) is not working!

Can anyone suggest anything?

Error: Unhandled exception type URISyntaxException

Code:

import java.net.URI;
import java.net.URISyntaxException;

URI uri = new URI("ws://asdasdsad:2000");
1 Like

see here https://examples.javacodegeeks.com/core-java/net/urisyntaxexception/java-net-urisyntaxexception-how-to-solve-urisyntaxexception/ , possibly better way.

i try

import java.net.URI;
import java.net.URISyntaxException;

URI uri;// = new URI("ws://asdasdsad:2000");

void setup() {
  try {
//  uri = new URI("http://www.javacodegeeks.com/");
    uri = new URI("ws://asdasdsad:2000");
    println("URI parsed succesfully!");
  } 
  catch (URISyntaxException e) {
    e.printStackTrace();
  }
}

looks good, but i not know what it is about,
but you also did not elaborate what you want to do …

1 Like

@devlogerio if you know the URI is valid (not user input), use URI::create instead.

eg.

uri = URI.create("ws://asdasdsad:2000");
1 Like