I rewiewed my code try to figure out why it thrown an exception . But i failed . This is for my assignment . Please help .
The exception is :
Exception in thread "main" java.lang.NullPointerException
at week11demo1.Main.<init>(Main.java:54)
at week11demo1.Main.main(Main.java:126)
Java Result: 1
Heres my codes :
package week11demo1;
<// Imports to cover our use of Swing and AWT. import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; // Our main class will be a JFrame, and since we want // to handle button clicks, we implement ActionListener. public class Main extends JFrame implements ActionListener { private JFrame window=new JFrame("Welcome to PasswordEvaluator "); private static final int WIDTH = 500; private static final int HEIGHT = 250; // Text areas for information display and input. private JTextArea criteria; private JTextArea password; private JPanel center; private JPanel south; private JLabel reminder; // Buttons for user interaction. private JButton check=new JButton("Check"); private JButton exit= new JButton("Exit"); public Main() { window.setSize(WIDTH, HEIGHT); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Don't let user resize window. //this.setResizable(false); // Set the layout to a flow layout. window.setLayout(new BorderLayout()); // Set up the text areas and add to form. criteria = new JTextArea(100,300); criteria.setText("Enter Your Password Below. And Click on the CHECK button to check your password strength The password should be at least six characters long. The password should contain at least one uppercase and at least one lowercaseletter. The password should have at least one digit."); //criteria.setLineWrap(true); window.add(criteria,BorderLayout.NORTH); center.setLayout(new FlowLayout()); reminder.setText("Password: "); password.setSize(50, 20); //password.setLineWrap(true); center.add(reminder,FlowLayout.LEFT); center.add(password,FlowLayout.RIGHT); // Set up and add the buttons. // Invoke actionPerformed for Main class. check.addActionListener(this); // Invoke actionPerformed for Main class. exit.addActionListener(this); south.setLayout(new FlowLayout()); south.add(check); south.add(exit); window.setVisible(true); } private static String IsValid(String pass){ int digitCount = 0; if(pass.length() >= 8) { for (char c : pass.toUpperCase().toCharArray()) { if((int)c >= 48 && (int)c <= 57) { // This is a digit digitCount++; } else if((int)c >= 65 && (int)c <= 90) { // This is an alphabetical character } else { // Other character return "Invalid: unacceptable character found '" + c + "'"; } } if(digitCount != 2) { return "Invalid: password must contain exactly 2 digits"; } } else { return "Invalid: password must contain 8 characters at least"; } return "Valid"; } public void actionPerformed(ActionEvent e) { Object button = e.getSource(); // Now test for which was clicked and act accordingly. if (button == exit) { System.exit(0); // Get out of Dodge. } else if (button == check) { String text = password.getText(); text = IsValid(text); } else {} } public static void main (String[] args) { new Main(); } }>