Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.4K
Vistas
¿Cómo agregar un ImageIcon en Java? este codigo no funciona

Quiero agregar un ImageIcon al Panel, pero obtuve esta Excepción (

 java.lang.NullPointerException: Cannot invoke "java.net.URL.toExternalForm()" because "location" is null Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "javax.swing.JLabel.setBounds(int, int, int, int)"

porque "this.LABEL2" es nulo y no se como solucionarlo, ayudenme por favor.

 import javax.swing.*; import java.awt.*; public class ShowQR extends JFrame{ private JPanel PANEL; private JLabel LABEL2; private ImageIcon ICON; public ShowQR(){ super("Choose background color"); ICON = new ImageIcon(getClass().getResource("qr-code2.png")); LABEL2= new JLabel(ICON); PANEL.setLayout(null); LABEL2.setBounds(50, 50, 50, 50); PANEL.add(LABEL2); add(PANEL); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(400,400); } }
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

public ImageIcon image = new ImageIcon(Test.class.getResource("give image path"));

Por favor, intente de esta manera. proporcione la ruta de la imagen en su estructura de archivos.

over 4 years ago · Santiago Trujillo Denunciar

0

esto podría ayudar

 ICON = new ImageIcon("specify icon path here "); //you might need to scale the icons size Image image = image.getImage().getScaledInstance(width, height,Image.SCALE_DEFAULT); ImageIcon ICON2 = new ImageIcon(image); LABEL2 = new JLabel(ICON2); LABEL2.setBounds(x,y,width,height);
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda