So I wrote this code before without methods and parameter passing and it worked splendid!
But once I started making it more organized using methods and passing parameters, I'm running into Null Pointer Exception. Why am I getting such an error?
import javax.swing.JFrame;
import javax.swing.JLabel;
public class test {
private static JLabel label;
public static void main(String[] args){
initializeLabel();
initializeFrame(label);
}
private static void initializeLabel(){
JLabel label = new JLabel();
label.setText("hi");
}
private static void initializeFrame(JLabel label){
JFrame frame = new JFrame();
frame.add(label);
frame.setVisible(true);
}
}