• Post Reply Bookmark Topic Watch Topic
  • New Topic

URL class is not working  RSS feed

 
Luke jaryszek
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am beginner and i don't know why downloading image from internet doesn't work.

I have 3 classes in Eclipse program:


```



```

and Test which is running these classes:


```

This part of code does not work:Causes error:

"Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
Unhandled exception type MalformedURLException"

Why this is happening?

If I change above code to:code will be working like a charm.

Please help,
I know that for you Java Gurus it is very simple but for me no

Best Regards,
Jacek Antek
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Always correct compiler errors before you try running a program. If you go back to Eclipse there will be a little red mark at the left of the line with the error. The problem is that any methods that use that URL declare they might throw a malformed URL Exception; you will have to catch such an Exception because it is a checked Exception.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are already catching the IOException, so there is no error about that.

By the way: I added code tags to your post. Always use them: doesn't it look better. I removed some empty lines and the bold tags because the bold doesn't work inside code tags.
 
Luke jaryszek
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Campbell Ritchie for your help!

I will try to catch this Error.

Jacek
 
Luke jaryszek
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am catching the IO Exception but still is a problem here.

Maybe there is a problem with kind of this exception ?

Jacek
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have already told you: you must catch the malformed URL exception. That is what Eclipse is telling you.
 
Luke jaryszek
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Campbell Ritchie!



I added bold cold to handle this exception but still is the same...
why ?

Jacek Antek
 
Luke jaryszek
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Added code:





Jacek
 
Luke jaryszek
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow i have solved it !!!



Correct code above.

Thank you once again !

Jacek
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done removing the throw instruction. Maybe you would like to put that opening of the URL into its own method, and put the search for the URL into a loop. Then you can return the URL object when it has been correctly instantiated.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!