Java ImageIO Method | What's wrong in my code !!!
Hi!
There must be something wrong with my code as terminal is not loading.
Any Help would be appreciated !!! Thanks.
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
class HappyMothersDay
{
public HappyMothersDay()
{
try
{
BufferedImage image = ImageIO.read(new File("C:/Users/Isaac/Pictures/etc.png")); // insert image root, folders, subfolders, file. jpeg, png, etc
}
catch (IOException e)
{
}
}
public static void main (String args[])
{
new HappyMothersDay();
}
}
Re: Java ImageIO Method | What's wrong in my code !!!
Hi Isaac,
Quickly scanning... try replacing...
ImageIO.read(new File("C:/Users/Isaac/Pictures/etc.png"));
with
ImageIO.read(new File("C://Users//Isaac//Pictures//etc.png"));
Re: Java ImageIO Method | What's wrong in my code !!!
Quote:
Originally Posted by
Art Vandelay
Hi Isaac,
Quickly scanning... try replacing...
ImageIO.read(new File("C:/Users/Isaac/Pictures/etc.png"));
with
ImageIO.read(new File("C://Users//Isaac//Pictures//etc.png"));
No, sorry, but I don't think that this will solve anything. Hang on...
Re: Java ImageIO Method | What's wrong in my code !!!
Quote:
Originally Posted by
ProgrammerIsaac
Hi!
There must be something wrong with my code as terminal is not loading.
Any Help would be appreciated !!! Thanks.
Code:
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
class HappyMothersDay
{
public HappyMothersDay()
{
try
{
BufferedImage image = ImageIO.read(new File("C:/Users/Isaac/Pictures/etc.png")); // insert image root, folders, subfolders, file. jpeg, png, etc
}
catch (IOException e)
{
}
}
public static void main (String args[])
{
new HappyMothersDay();
}
}
Please show the rest of your code with code tags if possible. Please tell us about any errors or exceptions that occur and post the complete messages.
Re: Java ImageIO Method | What's wrong in my code !!!
It's self contained and references no non-standard libraries. I think this is the entire program. Isaac - can you point out which line of code is supposed to load your terminal?
Re: Java ImageIO Method | What's wrong in my code !!!
Quote:
terminal is not loading.
Can you explain what is not happening?
One problem I see is the empty catch block. You should always call the printStackTrace() method in catch blocks to show any error messages.
Re: Java ImageIO Method | What's wrong in my code !!!
Hi Issac,
I ran you code--with a few alterations (see below)...and it worked. The terminal opened, etc.
However, please note that your class only generates a "BufferedImage as the result of decoding a supplied File with an ImageReader chosen automatically from among those currently registered." Your code doesn't currently do anything with the BufferedImage.
The exact code I used was:
Code:
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
class HappyMothersDay
{
public HappyMothersDay()
{
try
{
BufferedImage image = ImageIO.read(new File("D:\\Images\\blank.jpg"));
}
catch (IOException e)
{
System.out.println( "Error " + e);
}
}
public static void main (String args[])
{
new HappyMothersDay();
}
}
Did you wish to do something with the image once your read it?
Or...if your terminal isn't opening...are you sure it is compiling?
If it is not reading the image--because it is not there...the error would be:
Code:
Error javax.imageio.IIOException: Can't read input file!
BW, ArtV