|
Ralf,
Thanks for the advice...however, when I put the try -> catch in my code,
upon compilation I get the following error:
Exception java.lang.reflect.InvocationTargetException is never thrown in
the body of the corresponding try statement.
so, i guess I can't catch it...
Shane Cessna
iSeries Programmer
iSeries WAS Administrator
North American Lighting, Inc.
(618) 662-4483 x2776
shane_cessna@xxxxxxx
ralf.petter@xxxxxxxxxxx
Sent by: java400-l-bounces@xxxxxxxxxxxx
09/26/2005 08:24 AM
Please respond to
Java Programming on and around the iSeries / AS400
<java400-l@xxxxxxxxxxxx>
To
Java Programming on and around the iSeries / AS400
<java400-l@xxxxxxxxxxxx>
cc
Subject
Antwort: Java Exception question...
Hm!
catching an exception is pretty easy. Give the code line which throws the
exception into a try catch block. for example
try {
String targetFilename = imageDir +
filename.substring(0, filename.lastIndexOf(".")) + i + ".jpg";
JAI.create("filestore", image,
targetFilename, "JPEG");
}
catch(java.lang.reflect.InvocationTargetException e){
}
I think this will work, but is not best practice.
Greetings from Austria
Ralf M Petter
Shane_Cessna@xxxxxxx
Gesendet von: java400-l-bounces@xxxxxxxxxxxx
26.09.2005 15:13
Bitte antworten an
Java Programming on and around the iSeries / AS400
<java400-l@xxxxxxxxxxxx>
An
java400-l@xxxxxxxxxxxx
Kopie
Thema
Java Exception question...
I'm not sure if this is possible or not, but here goes. I have a loop
that converts multi-page TIF files to single page JPEG files...my problem
comes when the program converts the first page of the TIF successfully
then throws an exception
(java.lang.reflect.InvocationTargetException)...is there any possible way
to completely ignore this exception within my code? I realize this might
be taboo, but my method does what i want it to do before it hits this
exception...here's my code:
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.image.renderable.*;
import com.sun.media.jai.codec.*;
import javax.media.jai.*;
public class Tiff2JPEG {
public static boolean doTiff2JPEG(String filename, String
imageDir) {
String sourceFilename = imageDir + filename;
try {
FileSeekableStream stream = new
FileSeekableStream(sourceFilename);
imageDecoder dec =
ImageCodec.createImageDecoder("tiff", stream, null);
int numofpages = dec.getNumPages();
for (i = 0; i <= numofpages; i++) {
RenderedImage image =
dec.decodeAsRenderedImage(i);
String targetFilename = imageDir +
filename.substring(0, filename.lastIndexOf(".")) + i + ".jpg";
JAI.create("filestore", image,
targetFilename, "JPEG"); // this creates the JPG successfully, then
throws the exception...
}
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
public static void main(String args[]) {
if (doTiff2JPEG("multicolor14pages.tif", "C:\test
tiffs\")) {
System.out.println("JPG Creation Successful!");
} else {
System.out.println("JPG Creation Unsuccessful!");
}
}
}
Shane
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.