Hello guys, I'm having trouble with my final project using JDBC. I keep getting a null pointer exception and i can't figure out the problem. the code is quite long. any help would be appreciated
import java.sql.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Project implements ActionListener { Connection CONN ; Statement STATE; ResultSet RESULT; JFrame MainWindow; JButton NEXT = new JButton("NEXT"); JButton PREV = new JButton("PREV"); JButton FIRST = new JButton("FIRST"); JButton LAST = new JButton("LAST"); JButton UPDATE = new JButton("UPDATE"); JButton DELETE = new JButton("DELETE"); JButton NEW = new JButton("NEW"); JButton SAVE = new JButton("SAVE"); JTextField TF_ID; JTextField TF_NAME; JTextField TF_SYSTEM; JTextField TF_PUBLISHER; JTextField TF_PRICE; JTextField TF_CONDITION; JLabel JL_ID; JLabel JL_NAME; JLabel JL_SYSTEM; JLabel JL_PUBLISHER; JLabel JL_PRICE; JLabel JL_CONDITION; public static void main(String args[]) { [B]new Project();[/B] } public Project() { Connect(); [B]Select();[/B] Write(); Display(); } public void Write() { MainWindow = new JFrame(); MainWindow.setSize(700,200); MainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JL_ID = new JLabel("ID:"); JL_NAME = new JLabel("NAME:"); JL_SYSTEM = new JLabel("System:"); JL_PUBLISHER = new JLabel("Publisher:"); JL_PRICE = new JLabel("Price:"); JL_CONDITION = new JLabel("Condition:"); TF_ID = new JTextField(10); TF_NAME = new JTextField(50); TF_SYSTEM = new JTextField(20); TF_PUBLISHER = new JTextField(20); TF_PRICE = new JTextField(10); TF_CONDITION = new JTextField(5); JPanel BG = new JPanel(); BG.add(JL_ID); BG.add(TF_ID); BG.add(JL_NAME); BG.add(TF_NAME); BG.add(JL_SYSTEM); BG.add(TF_SYSTEM); BG.add(JL_PUBLISHER); BG.add(TF_PUBLISHER); BG.add(JL_PRICE); BG.add(TF_PRICE); BG.add(JL_CONDITION); BG.add(TF_CONDITION); BG.add(NEXT); BG.add(PREV); BG.add(FIRST); BG.add(LAST); BG.add(UPDATE); BG.add(DELETE); BG.add(NEW); BG.add(SAVE); NEXT.addActionListener(this); PREV.addActionListener(this); FIRST.addActionListener(this); LAST.addActionListener(this); UPDATE.addActionListener(this); DELETE.addActionListener(this); NEW.addActionListener(this); SAVE.addActionListener(this); MainWindow.add(BG); MainWindow.setVisible(true); } public void Connect() { try { Class.forName("org.sqlite.JDBC"); CONN = DriverManager.getConnection("jdbc:sqlite:C:\\Users\\all others enter\\!\\!\\Desktop\\ProjectDb"); } catch(Exception X0) {} } public void Select() { try { [B]STATE = CONN.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);[/B] String SQL = "SELECT * FROM games"; RESULT = STATE.executeQuery(SQL); } catch(Exception X) {} } public void Display() { try { RESULT.next(); TF_ID.setText(RESULT.getString("ID")); TF_NAME.setText(RESULT.getString("Name")); TF_SYSTEM.setText(RESULT.getString("System")); TF_PUBLISHER.setText(RESULT.getString("Publisher")); TF_PRICE.setText(RESULT.getString("Price")); TF_CONDITION.setText(RESULT.getString("Condition")); } catch(Exception X) {} } public void actionPerformed(ActionEvent X) { Object SRC = X.getSource(); if(SRC == NEXT) {NEXT_ACTION();} if(SRC == PREV) {PREV_ACTION();} if(SRC == FIRST) {FIRST_ACTION();} if(SRC == LAST) {LAST_ACTION();} if(SRC == UPDATE) {UPDATE_ACTION();} if(SRC == DELETE) {DELETE_ACTION();} if(SRC == NEW) {NEW_ACTION();} if(SRC == SAVE) {SAVE_ACTION();} } public void NEXT_ACTION() { try { if( RESULT.next()) { TF_ID.setText(RESULT.getString("ID")); TF_NAME.setText(RESULT.getString("Name")); TF_SYSTEM.setText(RESULT.getString("System")); TF_PUBLISHER.setText(RESULT.getString("Publisher")); TF_PRICE.setText(RESULT.getString("Price")); TF_CONDITION.setText(RESULT.getString("Condition")); } else { RESULT.previous(); JOptionPane.showMessageDialog(null,"Reached Last Record!"); } } catch(Exception X) { System.out.print(X); } } public void PREV_ACTION() { try { if( RESULT.previous()) { TF_ID.setText(RESULT.getString("ID")); TF_NAME.setText(RESULT.getString("Name")); TF_SYSTEM.setText(RESULT.getString("System")); TF_PUBLISHER.setText(RESULT.getString("Publisher")); TF_PRICE.setText(RESULT.getString("Price")); TF_CONDITION.setText(RESULT.getString("Condition")); } else { RESULT.next(); JOptionPane.showMessageDialog(null,"Reached First Record!"); } } catch(Exception X) { System.out.print(X); } } public void FIRST_ACTION() { try { RESULT.first(); TF_ID.setText(RESULT.getString("ID")); TF_NAME.setText(RESULT.getString("Name")); TF_SYSTEM.setText(RESULT.getString("System")); TF_PUBLISHER.setText(RESULT.getString("Publisher")); TF_PRICE.setText(RESULT.getString("Price")); TF_CONDITION.setText(RESULT.getString("Condition")); } catch(Exception X) { System.out.print(X); } } public void LAST_ACTION() { try { RESULT.last(); TF_ID.setText(RESULT.getString("ID")); TF_NAME.setText(RESULT.getString("Name")); TF_SYSTEM.setText(RESULT.getString("System")); TF_PUBLISHER.setText(RESULT.getString("Publisher")); TF_PRICE.setText(RESULT.getString("Price")); TF_CONDITION.setText(RESULT.getString("Condition")); } catch(Exception X) { System.out.print(X); } } public void UPDATE_ACTION() { try { RESULT.updateInt("ID", Integer.parseInt(TF_ID.getText())); RESULT.updateString("Name",TF_NAME.getText()); RESULT.updateString("System",TF_SYSTEM.getText()); RESULT.updateString("Publisher",TF_PUBLISHER.getText()); RESULT.updateDouble("Price", Double.parseDouble(TF_PRICE.getText())); RESULT.updateString("Condition",TF_CONDITION.getText()); RESULT.updateRow(); JOptionPane.showMessageDialog(null,"Updated!"); } catch(Exception X) { System.out.print(X);} } public void DELETE_ACTION() { try { RESULT.deleteRow(); RESULT.previous(); Display(); } catch(Exception X) { System.out.print(X);} } public void NEW_ACTION() { TF_ID.setText(""); TF_NAME.setText(""); TF_SYSTEM.setText(""); TF_PUBLISHER.setText(""); TF_PRICE.setText(""); TF_CONDITION.setText(""); } public void SAVE_ACTION() { try { RESULT.moveToInsertRow(); RESULT.updateInt("ID", Integer.parseInt(TF_ID.getText())); RESULT.updateString("Name",TF_NAME.getText()); RESULT.updateString("System",TF_SYSTEM.getText()); RESULT.updateString("Publisher",TF_PUBLISHER.getText()); RESULT.updateDouble("Price", Double.parseDouble(TF_PRICE.getText())); RESULT.updateString("Condition",TF_CONDITION.getText()); RESULT.insertRow(); STATE.close(); Select(); RESULT.last(); Display(); JOptionPane.showMessageDialog(null,"Updated"); } catch(Exception X) {System.out.print(X);} } }
the stack trace says
java.lang.NullPointerException
at Project.Select(Project.java:127)
at Project.(init)(Project.java:48)
at Project.main(Project.java:41)
I highlighted those lines in bold.