1

I was tring to add a gif at my java swing project just for fun, but every time I compile the program the gif file corrupts and I can't delete or do anything with it. My code is like:

jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/package/images/giphy.gif")));

and I get the following error code: obs. my main package and project name is braia

    at java.desktop/javax.swing.ImageIcon.<init>(ImageIcon.java:217)
    at braia.TelaBraia.initComponents(TelaBraia.java:34)
    at braia.TelaBraia.<init>(TelaBraia.java:18)
    at braia.TelaBraia$1.run(TelaBraia.java:83)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)


salipe
  • 19
  • 2
  • 4
    Method `getResource` is returning null since it cannot find file `giphy.gif`. This question has been asked and answered many times already, for example: https://stackoverflow.com/questions/4301329/java-class-getresource-returns-null – Abra Aug 20 '21 at 03:47

0 Answers0