Results 1 to 7 of 7
- 05-22-2012, 05:11 PM #1
Member
- Join Date
- May 2012
- Location
- Malta
- Posts
- 1
- Rep Power
- 0
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();
}
}
- 05-22-2012, 05:20 PM #2
Member
- Join Date
- May 2012
- Posts
- 18
- Rep Power
- 0
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 !!!
-
Re: Java ImageIO Method | What's wrong in my code !!!
- 05-22-2012, 07:34 PM #5
Senior Member
- Join Date
- Feb 2012
- Posts
- 117
- Rep Power
- 0
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?
- 05-22-2012, 07:37 PM #6
Re: Java ImageIO Method | What's wrong in my code !!!
Can you explain what is not happening?terminal is not loading.
One problem I see is the empty catch block. You should always call the printStackTrace() method in catch blocks to show any error messages.If you don't understand my response, don't ignore it, ask a question.
- 05-22-2012, 08:44 PM #7
Member
- Join Date
- May 2012
- Posts
- 18
- Rep Power
- 0
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:
Did you wish to do something with the image once your read it?Java 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(); } }
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:
BW, ArtVJava Code:Error javax.imageio.IIOException: Can't read input file!
Last edited by Art Vandelay; 05-22-2012 at 09:07 PM.
Similar Threads
-
What's wrong with my code? (Danish java-programmer would be greatly appriciated!)
By spande in forum New To JavaReplies: 32Last Post: 02-29-2012, 09:21 AM -
What is wrong in this code of java
By kank635 in forum New To JavaReplies: 1Last Post: 01-16-2012, 09:41 PM -
How to call an XML-RPC method from Java Code
By sreekanth.srk in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 12-31-2010, 12:36 PM -
Please look at my java code and tell me what's wrong
By xcointoss in forum Advanced JavaReplies: 3Last Post: 10-22-2010, 04:15 AM -
what wrong with my java code
By MAXZZXAM in forum New To JavaReplies: 3Last Post: 11-19-2009, 09:38 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks