-3

Below is the code, Spent Hour trying to track where is error... Code is much big... more then 45 Fields so more confused

Exception is `java.lang.NullPointerException`

code is

 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);
}

Result of Stack run:

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)
Ali Lotfi
  • 856
  • 3
  • 18
  • 40
rajit bansal
  • 21
  • 1
  • 1
  • 8
  • 2
    Can you put the stacktrace. it will have line number with that we can identify. There are lot of possibilites for null pointer exception in the code. – Kalaiarasan Manimaran Jan 12 '15 at 12:39
  • Bro Stacktrace Added – rajit bansal Jan 12 '15 at 12:49
  • possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – OldProgrammer Jan 12 '15 at 12:50
  • Already have Viewed that topic but unable to detect the problem, Have understood why this problem occur but could not identify the source of error in code – rajit bansal Jan 12 '15 at 12:52
  • You need to check what is written at Line number `895` of class `frmStudentRegistration.java` – gprathour Jan 12 '15 at 12:52
  • at 895 it is - addstudent.setString(4,DateOfAdmission.getDate().toString()); – rajit bansal Jan 12 '15 at 12:53
  • it is very difficult to guess for us. we can't see the line numbers. so better track the code in your machine. first remove the trim method, you may get null pointer for that also. later you find the code working add trim for each variable – Kalaiarasan Manimaran Jan 12 '15 at 12:56

1 Answers1

0

It got solved, error was regarding date which gave me null pointer Error, will post another Question for its answer so others are also benifited having same trouble

rajit bansal
  • 21
  • 1
  • 1
  • 8