Japplet jbutton icon

On the following line:

Image = new URL(getDocumentBase(),String.valueOf(i+1)+ ".jpg");

Why does it throw a 'MalformedURLException'?  Is there a way to set the
image on a jbutton using a japplet without a try,catch block?
LVL 8
List244Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
objectsConnect With a Mentor Commented:
The URL constructor will throw that exception if you provide an invalid url

try:

Image = getClass().getResource("/"+String.valueOf(i+1)+ ".jpg");
0
 
List244Author Commented:
That works, so is java incapable of throwing an exception without catching it?
0
 
objectsCommented:
correct, if a method declares that it throws a (checked) exception the calling method must catch it or declare that it may throw it.(RuntimeExceptions are nopt checked)
0
 
List244Author Commented:
Haha wow, that will take some getting used to, thanks again Objects.
0
 
List244Author Commented:
Have to say though, I am missing C++ right now...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.