Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Fubarable

Thread: PLEASE HELP ME-i got java.lang.NullPointerException

  1. #1
    Join Date
    Jul 2011
    Location
    India,Tamil Nadu
    Posts
    32
    Rep Power
    0

    Smile java.lang.NullPointerException

    HI,

    Thank you for your attention.
    Today, i am joined java forums.
    I got null pointer exception.

    Code:

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.sql.*;
    
    public class Confidence extends JFrame
    {
    Object[] data = new Object[1];
    String s[]={"Confidence"};
    int num[];
    String sql[];
    int i,j,k;
    
    
    
    
    DefaultTableModel d = new DefaultTableModel();
    JTable jtable1 = new JTable(d);
    JFrame frame = new JFrame(); 
    
    
    
    
    public Confidence() 
    {
    setVisible(true);
    setSize(300, 300);
    setLocation(100, 100);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    
    for(int c = 0; c < 1; c++)
    {
    d.addColumn(s[c]);
    }
    
    
    try
    {
    Connection con=null;
    Statement st1=null;
    ResultSet rs[]=null;
    PreparedStatement pst=null;
    int p1m=0;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con = DriverManager.getConnection("Jdbc:Odbc:Eight","sa" ,"");
    System.out.println("New Connection Create");
    
    
    
    
    sql[3]="SELECT count(P1) FROM CustomerTable WHERE Gender='F' and p1='Y' and Debt='N'";
    sql[4]="SELECT count(P1) FROM CustomerTable WHERE Gender='F' and p1='Y' and Debt='Y'";
    sql[5]="SELECT count(P1) FROM CustomerTable WHERE Gender='M' and p1='Y' and Debt='N'";
    
    
    sql[0]="SELECT count(P1) FROM CustomerTable WHERE Gender='F' and p1='Y'";
    sql[1]="SELECT count(P1) FROM CustomerTable WHERE Gender='F' and p1='Y'";
    sql[2]="SELECT count(P1) FROM CustomerTable WHERE Gender='M' and p1='Y'";
    
    
    
    j=3;
    for(i=0;i<=2;i++)
    {
    rs[i]=st1.executeQuery(sql[i]);
    if (rs[i].next())
    {
    num[i]= rs[i].getInt(1);
    rs[i].close();
    }
    rs[j]=st1.executeQuery(sql[j]);
    {
    if (rs[j].next())
    {
    int number = rs[j].getInt(1);
    data[1]=number+"/"+num[k];
    k++;
    }
    rs[j].close();
    j++;
    }
    
    d.addRow(data);
    
    }
    
    
    
    
    
    }
    catch(Exception ex)
    {
    System.out.println(ex);
    }
    
    add(new JScrollPane(jtable1));
    setVisible(true);
    }
    
    public static void main(String args[])
    {
    Confidence rw = new Confidence();
    }
    }
    With Regards,
    Nandhini
    Last edited by Fubarable; 07-30-2011 at 07:26 PM. Reason: quote tags changed to code tags

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    I recommend you edit your post above and add code tags so that the code is readable. Also you will want to indicate which line throws the NullPointerException.

  3. #3
    Join Date
    Jul 2011
    Location
    India,Tamil Nadu
    Posts
    32
    Rep Power
    0

    Smile

    Ok.Thank you.
    I don't know which line throws the NullPointerException.

    Output:
    New Connection Create
    java.lang.NullPointerException
    BUILD SUCCESSFUL (total time: 13 minutes 49 seconds)
    With Regards and Respects,
    Nandhini.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Change your catch block from this:
    Java Code:
          } catch (Exception ex) {
             System.out.println(ex);
          }
    to this:
    Java Code:
          } catch (ClassNotFoundException e) {
             e.printStackTrace();
          } catch (SQLException e) {
             e.printStackTrace();
          }
    Then post your exception message here and see if the exception message indicates which line is throwing the NPE (NullPointerException).

    I also edited your first post and changed your quote tags into code tags.
    nandhinianand likes this.

  5. #5
    Join Date
    Jul 2011
    Location
    India,Tamil Nadu
    Posts
    32
    Rep Power
    0

    Smile THANK YOU.Now my program is running successfully

    HI,
    THANK YOU.
    I changed the code as you said.
    I got the exception message which line throws.
    I corrected my mistake.
    Now my program is running successfully.

    Thanking you,
    With Regards and Respects,
    Nandhini.

Similar Threads

  1. Replies: 15
    Last Post: 01-13-2011, 06:28 PM
  2. java.lang.NullPointerException
    By vasavi.singh in forum New To Java
    Replies: 1
    Last Post: 02-27-2009, 12:36 PM
  3. java.lang.NullPointerException
    By stevemcc in forum AWT / Swing
    Replies: 2
    Last Post: 02-08-2008, 09:01 AM
  4. java.lang.NullPointerException
    By ravian in forum New To Java
    Replies: 1
    Last Post: 01-13-2008, 07:39 PM
  5. java.lang.NullPointerException
    By Felissa in forum Advanced Java
    Replies: 1
    Last Post: 07-05-2007, 06:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •