package Enrollment; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Login extends JFrame{ public String name; JTextField txtUsername; public Login(){ setLayout(new FlowLayout()); txtUsername = new JTextField(" ", 10); add(txtUsername); JButton btnLogin = new JButton("Login"); add(btnLogin); btnLogin.addActionListener(new ButtonListener()); } private class ButtonListener implements ActionListener{ @Override public void actionPerformed(ActionEvent e){ if(name == txtUsername.getText()){ Student StudentRegistration = new Student(); StudentRegistration.run(); StudentRegistration.lblName.setText(name); dispose(); }; } } public void run(){ setTitle("Login"); setBounds(200,200,350,200); setVisible(true); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }package Enrollment; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Student extends JFrame { Container con = null; JLabel picStudent; JLabel lblName; public Student(){ con = getContentPane(); con.setLayout(null); ImageIcon imh = new ImageIcon(getClass().getResource("Images/bg.jpg")); Icon studpic = new ImageIcon(getClass().getResource("Images/studpic.jpg")); setSize(imh.getIconWidth(), imh.getIconHeight()); JPanel panel = new JPanel(){ @Override public void paintComponent(Graphics g) { Image imh = new ImageIcon("Images/bg.jpg").getImage(); Dimension size = new Dimension(imh.getWidth(null), imh.getHeight(null)); setPreferredSize(size); setMinimumSize(size); setMaximumSize(size); setSize(size); setLayout(null); g.drawImage(imh, 0, 0, null); } }; con.add(panel); panel.setBounds(0, 0, imh.getIconWidth(), imh.getIconHeight()); JPanel panelcontent = new JPanel(new FlowLayout()); panelcontent.setBounds(0,0,200,200); panel.add(panelcontent); picStudent = new JLabel(studpic); lblName = new JLabel(); panelcontent.add(picStudent); panelcontent.add(lblName); } public void run(){ setTitle("Student Registration"); setBounds(0,0,575,431); setVisible(true); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }this is my error outputpackage Enrollment; public class Main { public static void main(String[] args){ Login login = new Login(); login.run(); } }
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:205)
at Enrollment.Student.<init>(Student.java:19)
at Enrollment.Login$ButtonListener.actionPerformed(Lo gin.java:29)
at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2018)