This site is really helping a lot of people! I have a simple program that I can't understand why I am getting the NullPointerException each time I try to pass a value from one form to another and setting it up as a text in a label. If I pass the value and do the pritln, I can actually see the result but if I place it in the jlabel as text, that's the time I get the error. Please Help! Thanks! Here is the code to pass the value to the other form.
[CODE = java]public class Micolocoi extends JApplet {
private String lblName;
public JLabel lblTime, lblRem1, lblRem2, lblRem3, lblRem4, lblRem5;
lblRem1 = new JLabel("0", SwingConstants.CENTER);
lblRem2 = new JLabel("0", SwingConstants.CENTER);
lblRem3 = new JLabel("0", SwingConstants.CENTER);
lblRem4 = new JLabel("0", SwingConstants.CENTER);
lblRem5 = new JLabel("0", SwingConstants.CENTER);
public void setRem1(String input) { lblName = input; System.out.println(input); } //TO GET THE VALUE FROM THE OTHER FORM
public String getRem1() { return lblName; }
public void setLblRem1(){ lblRem1.setText(getRem1()); } //TO SET UP THE VALUE AS THE TEXT OF THE LABEL
}
public static void main(String args[]){
Micolocoi micolocoi = new Micolocoi();
JFrame frame = new JFrame("MICOLOCOI");
Container container = frame.getContentPane();
container.add(micolocoi);
frame.setSize(600, 200);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
micolocoi.init();
micolocoi.start();
micolocoi.getDateTime();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
}
}
public class Choice extends JFrame {
btnPrepaid.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
selectionAction(e);
}
});
private void selectionAction(ActionEvent evt){
System.out.println(choice);
int choice = getChoice();
boolean bol = true;
switch (choice) {
case 1:
while(bol){
String str = JOptionPane.showInputDialog(null, "Input minutes ", "ALERT", 1);
if(str != null && Integer.parseInt(str) != 0){
JOptionPane.showMessageDialog(null, "Time will run for " +str +" minutes", "ALERT", 1);
mic.setRem1(str); //THIS IS WHAT I AM TRYING TO PASS TO THE OTHER FORM AND SET IT AS THE TEXT FOR THE LABEL SO I CAN ACTUALLY SUBTRACT 1 EACH MINUTE
mic.setLblRem1();
setVisible(false);
bol = false;
} else {
JOptionPane.showMessageDialog(null, "No input given", "ALERT", 1);
group.clearSelection();
}
}
break;
case 2:
while(bol){
String str = JOptionPane.showInputDialog(null, "Input minutes ", "ALERT", 1);
if(str != null && Integer.parseInt(str) != 0){
JOptionPane.showMessageDialog(null, "Time will run for " +str +" minutes", "ALERT", 1);
System.out.println("dfsadsf");
setVisible(false);
bol = false;
break;
} else {
JOptionPane.showMessageDialog(null, "No input given", "ALERT", 1);
group.clearSelection();
}
}
break;
}.... [/CODE]