空指针错误Swing和数据库

时间:2015-01-12 12:38:15

标签: java nullpointerexception

下面是代码,Spent Hour试图追踪错误的位置...... 代码很大......超过45个字段更加混乱

Exception is `java.lang.NullPointerException`

代码是

 String Scholno=getScholarNo();
 ScholarNo.setText(Scholno);
 addstudent = cnn.prepareStatement ("Insert into student(
    ScholarNo, Student_Name, Application_No, DateOfAdmission,
    Fathers_Name, Gender, DOB, Address, Session, Contact_no, Email, Course,
    Branch, Submitted_Documents, Nationality, GuardianName, GuardianContactNo,
    GuardianAddress, High_School_name, HS_Year_of_passing, HS_Percentage,
    HS_Board, Higher_secondary_Name, H_year_of_passing, H_percentage,
    H_board, Graduation, G_year_of_passing, G_percentage, G_University,
    Post_graduation, PG_year_of_passing, PG_percentage, PG_university,
    mother_name, religion, category, semester, section, status,Photo) ;
    values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");

  addstudent.setString(1,ScholarNo.getText());
  addstudent.setString(2,StudentName.getText().trim());
  addstudent.setString(3,AdmissionNo.getText().trim());
  addstudent.setString(4,DateOfAdmission.getDate().toString());
  addstudent.setString(5,FatherName.getText().trim());
  addstudent.setString(6,Gender.getSelectedItem().toString().trim());
  addstudent.setString(7, DOB.getDate().toString());
  addstudent.setString(8,Address.getText().trim());
  addstudent.setString(9,Session.getSelectedItem().toString());
  addstudent.setString(10,ContactNo.getText().trim());
  addstudent.setString(11,Email.getText().trim());
  addstudent.setString(12,Course.getSelectedItem().toString().trim());
  addstudent.setString(13,Branch.getSelectedItem().toString().trim());
  addstudent.setString(14,DocumentSubmitted.getText().trim());
  addstudent.setString(15,Nationality.getText().trim());
  addstudent.setString(16,GuardianName.getText().trim());
  addstudent.setString(17,GuardianContactNo.getText().trim());
  addstudent.setString(18,GuardianAddress.getText().trim());
  addstudent.setString(19,HS.getText().trim());
  addstudent.setString(20,HSYOP.getText().trim());
  addstudent.setString(21,HSPercentage.getText().trim());
  addstudent.setString(22,HSBoard.getText().trim());
  addstudent.setString(23,HSS.getText().trim());
  addstudent.setString(24,HSSYOP.getText().trim());
  addstudent.setString(25,HSSPercentage.getText().trim());
  addstudent.setString(26,HSSBoard.getText().trim());
  addstudent.setString(27,UG.getSelectedItem().toString().trim());
  addstudent.setString(28,GYOP.getText().trim());
  addstudent.setString(29,GPercentage.getText().trim());
  addstudent.setString(30,GUniy.getText().trim());
  addstudent.setString(31,PG.getSelectedItem().toString().trim());
  addstudent.setString(32,PGYOP.getText().trim());
  addstudent.setString(33,PGpercentage.getText().trim());
  addstudent.setString(34,PGUniy.getText().trim());
  addstudent.setString(35,MotherName.getText().trim());
  addstudent.setString(36,Religion.getSelectedItem().toString().trim());
  addstudent.setString(37,Category.getSelectedItem().toString().trim());
  addstudent.setString(38,Semester.getSelectedItem().toString().trim());
  addstudent.setString(39,Section.getSelectedItem().toString().trim());
  addstudent.setString(40,Status.getSelectedItem().toString().trim());
  addstudent.setBytes(41,person_image);
  addstudent.executeUpdate();
} catch(Exception e) {
        //e.printStackTrace();
       JOptionPane.showMessageDialog(null, e);
}

堆叠结果 运行:

java.lang.NullPointerException
    at projectmanagment.frmStudentRegistration.btnupdateActionPerformed(frmStudentRegistration.java:895)
    at projectmanagment.frmStudentRegistration.btnupdateActionPerformed(frmStudentRegistration.java:895)
    at projectmanagment.frmStudentRegistration.access$300(frmStudentRegistration.java:25)
    at projectmanagment.frmStudentRegistration$4.actionPerformed(frmStudentRegistration.java:563)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6516)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
    at java.awt.Component.processEvent(Component.java:6281)
    at java.awt.Container.processEvent(Container.java:2229)
    at java.awt.Component.dispatchEventImpl(Component.java:4872)
    at java.awt.Container.dispatchEventImpl(Container.java:2287)
    at java.awt.Component.dispatchEvent(Component.java:4698)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.java:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2719)
    at java.awt.Component.dispatchEvent(Component.java:4698)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:694)
    at java.awt.EventQueue$3.run(EventQueue.java:692)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:708)
    at java.awt.EventQueue$4.run(EventQueue.java:706)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

1 个答案:

答案 0 :(得分:0)

它得到了解决,错误是关于日期给了我空指针错误,将发布另一个问题的答案,所以其他人也受益同样的麻烦