简体   繁体   中英

Java: image not loading in Eclipse

I searched a lot on Stack Overflow and followed the answer given here . But I am still getting IllegalArgumentException : input==null! for the following lines:

BufferedImage image=ImageIO.read(this.getClass().getResource("/images/bg.jpg"));    
ImageIcon logo=new ImageIcon(ImageIO.read(this.getClass().getResource("/images/tucan.png")));

I tried everything but still no success. My directory structure is this:
News -->res-->images-->bg.jpg,tucan.png

在此处输入图片说明

You have to add your res folder to the list of source folders .

Right Click -> Build Path -> Use as source folder

If you don't, then Eclipse won't copy the folder into the output folder and you can't access them in the way you tried to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM