Results 1 to 3 of 3
  1. #1
    jrooi1 is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default problem with reading image

    hey guys,

    i have a problem reading an image file to my program.

    Java Code:
    public class IOClass {
    	private File file;
    	private BufferedImage image;
    
    	
    	public BufferedImage inputImage(){
    		
    		try {
    			file = new File("leaf.jpg");
    		    image = ImageIO.read(file);
    		} catch (IOException e) {
    		}
    		return image;
    	}
    	public static void main(String[] args){
    		IOClass io = new IOClass();
    		
    		BufferedImage i = io.inputImage();
    		if(i== null){
    			System.out.println(" image fail!!!");
    		}
    	}
    }
    i've tested both file and image variables. the file variable exist while the image variable returns null.

    does anyone have any idea what is wrong with my code? i've been scratching my head for over two hours trying to figure out
    what is the problem.

    the leaf.jpg file is in the src folder if this info helps, and im using eclipse.

    URGENT HELP!!

    any ideas will be gratefully appreciated. thx.

    regards,
    josh.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: problem with reading image

    Are you sure the file is in the folder where the program is trying to read it?
    Print out the absolute path for the file object to see where the program is looking for the file.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jrooi1 is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Re: problem with reading image

    Quote Originally Posted by Norm View Post
    Are you sure the file is in the folder where the program is trying to read it?
    Print out the absolute path for the file object to see where the program is looking for the file.
    you r a champ!!!! it worked!!! lol!! thx a lot.

Similar Threads

  1. Reading MS doc image from Java
    By gopal026 in forum New To Java
    Replies: 1
    Last Post: 12-06-2011, 02:06 PM
  2. Help : reading image and draw it on GUI
    By Rodrigo91 in forum Java 2D
    Replies: 0
    Last Post: 03-26-2011, 11:01 PM
  3. Replies: 5
    Last Post: 08-21-2009, 12:03 PM
  4. Image reading from URL problem
    By paras in forum Advanced Java
    Replies: 4
    Last Post: 04-18-2009, 08:26 AM
  5. [SOLVED] Image reading from URL problem
    By paras in forum New To Java
    Replies: 3
    Last Post: 04-18-2009, 06:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •