Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Help with url

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with url

    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
    Last edited by nigele2; August 25th, 2014 at 02:01 PM. Reason: tipo


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,403
    Thanks
    49
    Thanked 2,213 Times in 2,186 Posts

    Default Re: Help with url

    having no luck
    Please copy the full text of the error messages and paste it here.

    Read the API doc for the URL class. Also it has a link to a site that defines what goes in a valid URL.
    The String you show: '127.0.0.1:6500' is missing the protocol.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with url

    Norm many thanks. It's amazing just a little push in the right line of thinking and we are there.

    Having fed the embedded browser simple strings like 'bbc.com' and getting the correct result I thought I should be able to pass '127.0.0.1:6500' as I do with all external browsers. Guess I'll have to write a parser to pick up whatever the users throws in and build to the protocol. But much appreciated and enjoy your day.

Similar Threads

  1. how to read URL
    By Django in forum What's Wrong With My Code?
    Replies: 10
    Last Post: March 10th, 2013, 07:15 AM
  2. Url Image stream? Getting an Image url.
    By turtlemaster in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 30th, 2012, 09:43 AM
  3. url
    By nasi in forum Java Theory & Questions
    Replies: 3
    Last Post: April 12th, 2010, 02:43 AM
  4. how to get url?
    By chinni in forum Java Networking
    Replies: 2
    Last Post: November 4th, 2009, 11:06 AM

Tags for this Thread