Hi. Hope someone can give me a clue.
I have a java standalone using Eclipse EE. I have an embedded browser which works fine if I throw 'bbc.com' at it.
I have a text box where the users enters the url. A common entry would be '127.0.0.1:6500'.
However using URI and URL having no luck and just don't see it. Tried lots of combinations. Any hints very welcome.
Here my Listener.
buttonurl.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { URI uri = null; URL url = null; try { uri = new URI(texturl.getText()); } catch (URISyntaxException e1) { System.out.println("failed setting uri"); e1.printStackTrace(); } System.out.println(uri.toString()); try { url = uri.toURL(); } catch (MalformedURLException e1) { System.out.println("failed creating url"); e1.printStackTrace(); } browser.setUrl(url.toString()); } });
This code even with simple bbc.com gives me the stack trace below. But if I pass bbc.com as a simple string no problem,
Exception in thread "main" java.lang.IllegalArgumentException: URI is not absolute
at java.net.URI.toURL(Unknown Source)
at Path01class$31.widgetSelected(Path01class.java:156 6)
at org.eclipse.swt.widgets.TypedListener.handleEvent( TypedListener.java:248)
at org.eclipse.swt.widgets.EventTable.sendEvent(Event Table.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display. java:4353)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.ja va:1061)
at org.eclipse.swt.widgets.Display.runDeferredEvents( Display.java:4172)
at org.eclipse.swt.widgets.Display.readAndDispatch(Di splay.java:3761)
at Path01class.main(Path01class.java:2352)
bbc.com
And if I try 127.0.0.1:6500 I get
java.net.URISyntaxException: Illegal character in scheme name at index 0: 127.0.0.1:6500
failed setting uri