Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: IconImage

  1. #1
    Member
    Join Date
    Feb 2010
    Posts
    81
    Thanks
    18
    Thanked 1 Time in 1 Post

    Default IconImage

    Hi, I was wondering if any of you guys could figure out what is wrong with this line of code:

    try {
    frame.setIconImage(ImageIO.read(frame.getClass().getResource("C:\\Users\\John\\Downloads\\calcicon.ico")));
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    I can guarantee that the file location is right, so I'm not sure which part of it I'm doing wrong.

    Here is what the exception is:

     

    java.lang.IllegalArgumentException: input == null!
    at javax.imageio.ImageIO.read(Unknown Source)
    at JFrameClaculator.Calculator.createAndShowGUI(Calcu lator.java:524) //*
    at JFrameClaculator.Calculator.access$0(Calculator.ja va:63) //**
    at JFrameClaculator.Calculator$1.run(Calculator.java: 31) //***
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)



    * = The line I mentioned above
    ** = private static void createAndShowGUI() {
    *** = createAndShowGUI();

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: IconImage

    When you call getResource, you are looking for a file relative to the class itself. To find a file using an absolute path, use ImageIO.read(//path to file). This however can make your application less portable, so you can place your image relative to the class file and use the getResource (I typically create an image folder at the root of my package and call getResource("/image/imagename")

  3. The Following User Says Thank You to copeg For This Useful Post:

    The_Mexican (December 5th, 2010)