thank you.
See, I've got this method (below), that actually creates this image for me.
private static BufferedImage loadImage(final URL url) throws Exception{ //IOException {
BufferedImage image;
// Load the image through Image I/O
image = ImageIO.read(url);
//image = imageIO.read(url);
// Check that the image was loaded and that we can get a GC
if (image != null && !GraphicsEnvironment.isHeadless()) {
final GraphicsConfiguration gc = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.getDefaultConfiguration();
// This probably can't be null if it's not headless
// Not sure though so check anyway
if (gc != null) {
// Attempt to create compatible image with same transparency
final BufferedImage img = gc.createCompatibleImage(
image.getWidth(), image.getHeight(),
image.getTransparency());
// Check that img was created and isn't the same type
// If it's the same type we don't need to convert obviously
if (img != null && image.getType() != img.getType()) {
// Use ColorConvertOp to convert the rasters from one
// color space to the other
// This is faster than using Graphics to draw on the new
// image in many cases, sometimes 100x faster
ColorConvertOp op = new ColorConvertOp(
image.getColorModel().getColorSpace(),
img.getColorModel().getColorSpace(), null);
op.filter(image, img);
image = img;
}
}
}
return image;
}
But, I need to call this from within the same class:
URL base;
try{
base = new URL ("http://home.cogeco.ca/~someplace/folder");
catch(Exception n)
{
System.out.println("Can't construct URL, first time around.");
}
try{
ll = loadImage(base); // right exception after calling method?
}
catch(Exception n)
{
System.out.println("problems");
}
For some reason, I can't figure out if I'm handling the exception properly. Any ideas why I'm getting the following error?
load: tetrisapp.PictureData.class can't be instantiated.
java.lang.InstantiationException: tetrisapp.PictureData
at java.lang.Class.newInstance0(Class.java:340)
at java.lang.Class.newInstance(Class.java:308)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:778)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:707)
at sun.applet.AppletPanel.run(AppletPanel.java:361)
at java.lang.Thread.run(Thread.java:619)
Tell me if you need more code. I'm guessing that the error is coming from the improper handling of the exception.
Message was edited by:
ManRed
Message was edited by:
ManRed