Here is the error I'm getting

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: input == null!

And here is the code

 try
            {           
                //myPicture = ImageIO.read(new File("Companylogo_FINAL.jpg"));
              myPicture = ImageIO.read(getClass().getResource("/resources/Companylogo_FINAL.jpg"));
                ImageIcon img = new ImageIcon(myPicture);
                frame.setIconImage(img.getImage());
            } 
            catch (IOException e1)
            {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }


            JLabel lbl = new JLabel(new ImageIcon(myPicture));

As you can see I have changed this line

myPicture = ImageIO.read(new File("Companylogo_FINAL.jpg"));

To this

 myPicture = ImageIO.read(getClass().getResource("/resources/Companylogo_FINAL.jpg"));

As by earlier code I was getting error "cannot read file"

Recommended Answers

All 11 Replies

Try this

myPicture = ImageIO.read(getClass().getResource("Companylogo_FINAL.jpg"));

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: input == null!

Same error

Exactly which line does the error message point to?

It points to

myPicture = ImageIO.read(getClass().getResource("/resources/Companylogo_FINAL.jpg"));

Almost certainly a problem with the path to the jpeg (assuming the jpeg itself is OK). That form of reference works well and requires a "resouces" folder to be in the classpath - best alongside the folder for the outermost package where the class files are stored. Sorry if that's confusing wording.
Eg
your .java file begins

package myApp;

class myClass {
   ...

Your run-time folder structure should look like

<some folder in the classpath>
   myApp
      myClass.class
   resources
      logo.jpg
1.Classfile folder
2.Images Folder >Companylogo_FINAL.jpg.

Don't you have any package specified for your code?

No Pakage specified,Just Default.
EDIT:
Please someone expalain ,it is confusing to me.
Now I have tried this code which was giving me error earlier(Cannot read file)...now works.

myPicture = ImageIO.read(new File("Companylogo_FINAL.jpg"));

At least not giving me error on that line anymore.

99% of problems like this come down to Java looking for the file in the wrong place. (or at least not the place you expected). Check out the File API doc for a full description of how partial paths are completed.

The getResource solution is better (if you can make it work) because that will continue to work when you package your code and resources in a jar file.

Yes that is the better solution.
But the problem is still there with that code.(Still working on that).
Meanwhile another errors to take care off.

Now I have solved the porblem with my Image from my resource.

I was doing import the wrong way..manually copy and past the image into the folder(Wrong way).
Correct way is to use import in the file then import>your folder name where you want to import it and done.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.