Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Japplet jbutton icon

Posted on 2006-07-05
5
Medium Priority
?
217 Views
Last Modified: 2010-03-31
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?
0
Comment
Question by:List244
  • 3
  • 2
5 Comments
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 17048120
The URL constructor will throw that exception if you provide an invalid url

try:

Image = getClass().getResource("/"+String.valueOf(i+1)+ ".jpg");
0
 
LVL 8

Author Comment

by:List244
ID: 17048137
That works, so is java incapable of throwing an exception without catching it?
0
 
LVL 92

Expert Comment

by:objects
ID: 17048178
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
 
LVL 8

Author Comment

by:List244
ID: 17048186
Haha wow, that will take some getting used to, thanks again Objects.
0
 
LVL 8

Author Comment

by:List244
ID: 17048190
Have to say though, I am missing C++ right now...
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question