Skip to content

Can’t get a image from resources

I have problem to get an image from another package of my Eclipse project! I saw this post here My code is this

288    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
289    InputStream input = classLoader.getResourceAsStream("images/sun.png");
290    PDJpeg img = new PDJpeg(doc, input);

I getting this exception:

Exception in thread "main" java.lang.IllegalStateException: 
at MainClasses.CreateTableOnPDF.main(

I don’t know what I am doing wrong? Maybe is the a lot hour a have spend already infront of my monitor.

Here is my project structure: enter image description here

Thanks for your attention and time!


Please check the API docs, you should put JPEG data, not PNG data.

public PDJpeg(PDDocument doc, InputStream is) throws IOException


  • doc – The document to create the image as part of.
  • is – The stream that contains the JPEG data.


  • IOException – If there is an error reading the JPEG data.