Home > Archive > Java Help > August 2006 > ImageIO problems
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hi,
First let me say, I am new to Java. I am trying to write a little applet
for a web page that will do some special filtering on a graphic. In any
event, I am trying to load a graphic VIA ImageIO.read(), but keep getting
errors. Here is some sample code I wrote to test out ImageIO.read();:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
import java.util.*;
public class GraphicTest extends Applet {
public void init() {
Image tileSheet = ImageIO.read(new File("blue.gif"));
}
public void paint(Graphics g) {
}
}
Ok, no big deal, really only one line that does anything... I get this
error:
GraphicTest.java:12: unreported exceptions java.io.IOException; must be
caught or declared to be thrown
Image tileSheet = ImageIO.read(new File("blue.gif");
^
That carrot should be under the ( before new.
Basically, I have been trying (hit or miss) various syntax to try to get
ImageIO to work... but nothing. I either get errors like this or that it is
an undefined symbol. If I copy examples strait out of books it seems not to
even work. Can anyone help?
| |
| Knute Johnson 2006-08-22, 10:01 pm |
| Xrak wrote:
> Hi,
>
> First let me say, I am new to Java. I am trying to write a little applet
> for a web page that will do some special filtering on a graphic. In any
> event, I am trying to load a graphic VIA ImageIO.read(), but keep getting
> errors. Here is some sample code I wrote to test out ImageIO.read();:
>
> import java.applet.*;
> import java.awt.*;
> import java.awt.event.*;
> import java.awt.image.*;
> import javax.imageio.*;
> import java.io.*;
> import java.util.*;
>
> public class GraphicTest extends Applet {
>
> public void init() {
try {
> Image tileSheet = ImageIO.read(new File("blue.gif"));
catch (IOException ioe) {
// do something with the exception
}
> }
> public void paint(Graphics g) {
> }
> }
>
> Ok, no big deal, really only one line that does anything... I get this
> error:
>
> GraphicTest.java:12: unreported exceptions java.io.IOException; must be
> caught or declared to be thrown
> Image tileSheet = ImageIO.read(new File("blue.gif");
> ^
> That carrot should be under the ( before new.
>
> Basically, I have been trying (hit or miss) various syntax to try to get
> ImageIO to work... but nothing. I either get errors like this or that it is
> an undefined symbol. If I copy examples strait out of books it seems not to
> even work. Can anyone help?
>
>
--
Knute Johnson
email s/nospam/knute/
| |
| Oliver Wong 2006-08-22, 10:01 pm |
|
"Xrak" <bg229@scn.org> wrote in message
news:G8IGg.9318$Qf.2699@newsread2.news.pas.earthlink.net...
>
> I get this error:
>
> GraphicTest.java:12: unreported exceptions java.io.IOException; must be
> caught or declared to be thrown
[...]
> Basically, I have been trying (hit or miss) various syntax to try to get
> ImageIO to work... but nothing. I either get errors like this or that it
> is an undefined symbol. If I copy examples strait out of books it seems
> not to even work. Can anyone help?
Knute gave gave you the correct code, but if you want to actually
understand why it works and how to avoid problems like this in the future, I
suggest you read
http://java.sun.com/docs/books/tuto...ial/exceptions/
- Oliver
| |
| Rhino 2006-08-22, 10:01 pm |
|
"Xrak" <bg229@scn.org> wrote in message
news:G8IGg.9318$Qf.2699@newsread2.news.pas.earthlink.net...
> Hi,
>
> First let me say, I am new to Java. I am trying to write a little applet
> for a web page that will do some special filtering on a graphic. In any
> event, I am trying to load a graphic VIA ImageIO.read(), but keep getting
> errors. Here is some sample code I wrote to test out ImageIO.read();:
>
> import java.applet.*;
> import java.awt.*;
> import java.awt.event.*;
> import java.awt.image.*;
> import javax.imageio.*;
> import java.io.*;
> import java.util.*;
>
> public class GraphicTest extends Applet {
>
> public void init() {
> Image tileSheet = ImageIO.read(new File("blue.gif"));
> }
> public void paint(Graphics g) {
> }
> }
>
> Ok, no big deal, really only one line that does anything... I get this
> error:
>
> GraphicTest.java:12: unreported exceptions java.io.IOException; must be
> caught or declared to be thrown
> Image tileSheet = ImageIO.read(new File("blue.gif");
> ^
You missed the closing parenthesis for the outer set of parentheses on that
line.
> That carrot should be under the ( before new.
>
FYI: It's spelled "caret" and it's properly pronounced "care-RAY". A carrot
is an orange-coloured vegetable.
> Basically, I have been trying (hit or miss) various syntax to try to get
> ImageIO to work... but nothing. I either get errors like this or that it
> is an undefined symbol. If I copy examples strait out of books it seems
> not to even work. Can anyone help?
>
--
Rhino
| |
| Andrew Thompson 2006-08-23, 4:02 am |
| Xrak wrote:
....
> First let me say, I am new to Java. I am trying to write a little applet
Arrrgh! The combination of 'new to Java' and 'applet'.
GUI'd applications should only be attempted after gaining
a basic understanding of Java, and Applets trip up even
experienced GUI developers.
> for a web page that will do some special filtering on a graphic. In any
> event, I am trying to load a graphic VIA ImageIO.read(), but keep getting
> errors. Here is some sample code I wrote to test out ImageIO.read();:
This applet may need to be signed, depending on
how it accesses images.
An unsigned applet can get images via URL from the
same site that served the applet. For anything else,
the applet will need to be signed and accepted by the
user.
Andrew T.
|
|
|
|
|