Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
Publicado por Nick Cardenas (2 intervenciones) el 24/05/2021 00:39:15
/*Estoy elaborando un programa para una Dulcería en JFrame, tengo este JFrame llamado ModalFrm cuya funcion es servir como JDialog como un pop up en el que se me aparece una leyenda un icono y dos botones uno para aceptar y otro para cancelar pero a la hora de presionar la opcion que me debería arrojar o abrir esta ventana marca error y no se despliega, si comento desde el switch hasta el final de la sig linea :
lblIcono.setIcon(new javax.swing.ImageIcon(getClass().getResource("UrlImagen"))); // NOI18N
Se despliega pero no como debería funcionar entonces supongo que el error esta en el switch pero no logro arreglarlo para que funcione correctamente
*/
lblIcono.setIcon(new javax.swing.ImageIcon(getClass().getResource("UrlImagen"))); // NOI18N
Se despliega pero no como debería funcionar entonces supongo que el error esta en el switch pero no logro arreglarlo para que funcione correctamente
*/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package Vistas;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
/**
*
* @author Nick
*/
public class ModalFrm extends javax.swing.JDialog {
public int opcionSel = -1;
String UrlImagen = "";
public ModalFrm(JFrame padre, boolean modal,String Mensaje,String tipo) {
super(padre,modal);
initComponents();
setIconImage(new ImageIcon(getClass().getResource("/Imagenes/IconoTop.png")).getImage());
lblMensaje.setText(Mensaje);
switch(tipo){
case "error": UrlImagen = "/Imagenes/x64/Error.png";break;
case "question": UrlImagen = "/Imagenes/x64/question.png";
case "succes": UrlImagen = "/Imagenes/x64/Aceptar.png";break;
case "info": UrlImagen = "/Imagenes/x64/info.png";break;
case "warning": UrlImagen = "/Imagenes/x64/warning.png";break;
default: UrlImagen= "/Imagenes/x64/info.png";break;
}
lblIcono.setIcon(new javax.swing.ImageIcon(getClass().getResource("UrlImagen"))); // NOI18N
}
//CODIGO GENERADO
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
BtnCancelar = new javax.swing.JButton();
BtnAceptar = new javax.swing.JButton();
lblMensaje = new javax.swing.JLabel();
lblIcono = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false);
jPanel1.setBackground(new java.awt.Color(255, 204, 51));
BtnCancelar.setBackground(new java.awt.Color(255, 204, 51));
BtnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/x32/delete.png"))); // NOI18N
BtnCancelar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnCancelarActionPerformed(evt);
}
});
BtnAceptar.setBackground(new java.awt.Color(255, 204, 51));
BtnAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/x32/Save32.png"))); // NOI18N
BtnAceptar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnAceptarActionPerformed(evt);
}
});
lblMensaje.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblMensaje.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lblMensaje.setText("<Mensaje>");
lblIcono.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/x64/Error.png"))); // NOI18N
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblMensaje, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(52, 52, 52)
.addComponent(BtnAceptar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(BtnCancelar)
.addGap(46, 46, 46))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(205, Short.MAX_VALUE)
.addComponent(lblIcono)
.addGap(209, 209, 209))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(lblIcono)
.addGap(18, 18, 18)
.addComponent(lblMensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(BtnAceptar)
.addComponent(BtnCancelar))
.addGap(32, 32, 32))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void BtnAceptarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void BtnCancelarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
// Variables declaration - do not modify
private javax.swing.JButton BtnAceptar;
private javax.swing.JButton BtnCancelar;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel lblIcono;
private javax.swing.JLabel lblMensaje;
// End of variables declaration
}
Valora esta pregunta
0