Results 1 to 4 of 4
  1. #1
    adeeb is offline Member
    Join Date
    May 2008
    Posts
    29
    Rep Power
    0

    Default NullPointerException

    Hi,
    In my program i don't have any errors while compiling but i am getting this error while compiling:
    Here is the Error code:
    "Exception in thread "main" java.lang.NullPointerException
    at library.<init>(library.java:205)
    at library.main(library.java:515)
    Press any key to continue..."

    The program code is below starting from the line number 205 as indicated in error. The below code is written under ActionListener:

    find.addActionListener(new ActionListener()
    {

    public void actionPerformed(ActionEvent e)
    {
    Vector columnNames = new Vector();
    Vector data = new Vector();
    try
    {
    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    Class.forName( driver );
    Connection connection = DriverManager.getConnection( "jdbc dbc:addissue","library", "bismillah" );

    String sql = "Select * from addissue ORDER BY rollno ASC";
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery( sql );
    ResultSetMetaData md = rs.getMetaData();
    int columns = md.getColumnCount();

    // Get column names

    for (int i = 1; i <= columns; i++)
    {
    columnNames.addElement( md.getColumnName(i) );
    }

    // Get row data

    while (rs.next())
    {
    Vector row = new Vector(columns);

    for (int i = 1; i <= columns; i++)
    {
    row.addElement( rs.getObject(i) );
    }

    data.addElement( row );
    }

    rs.close();
    stmt.close();
    }
    catch(Exception ce)
    {
    System.out.println( ce );
    }

    JTable tab = new JTable(data, columnNames);
    JScrollPane jsp = new JScrollPane(tab);

    }
    });

    ftf = new JTextField(20);
    ftf1 = new JTextField(20);
    froll = new JLabel("Roll No");
    fname = new JLabel("Name");
    find = new JButton("Find");

    GroupLayout gl5 = new GroupLayout(jp5);
    jp5.setLayout(gl5);
    gl5.setAutoCreateGaps(true);
    gl5.setAutoCreateContainerGaps(true);
    gl5.setHorizontalGroup(gl5.createSequentialGroup()
    .addGroup(gl5.createParallelGroup(LEADING)
    .addComponent(froll)
    .addComponent(fname))
    .addGroup(gl5.createParallelGroup(LEADING)
    .addComponent(ftf)
    .addComponent(ftf1)
    .addComponent(find, (CENTER))
    .addComponent(jsp))
    );

    gl5.setVerticalGroup(gl5.createSequentialGroup()
    .addGroup(gl5.createParallelGroup(BASELINE)
    .addComponent(froll)
    .addComponent(ftf))
    .addGroup(gl5.createParallelGroup(BASELINE)
    .addComponent(fname)
    .addComponent(ftf1))
    .addGroup(gl5.createParallelGroup(BASELINE)
    .addComponent(find))
    .addGroup(gl5.createParallelGroup(BASELINE)
    .addComponent(jsp))
    );
    this was the code for adding a table with few other components to a panel.
    Thanks and Regard.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    One of your member not get the correct value, and set null at run time. Do you have debug and see where it happened?

  3. #3
    adeeb is offline Member
    Join Date
    May 2008
    Posts
    29
    Rep Power
    0

    Default

    Hey,
    Eranga
    Now i am getting the following error

    Exception in thread "main" java.lang.IllegalArgumentException: Component must be
    non-null
    at javax.swing.GroupLayout$ComponentSpring.<init>(Gro upLayout.java:2878)

    at javax.swing.GroupLayout$ComponentSpring.<init>(Gro upLayout.java:2858)

    at javax.swing.GroupLayout$Group.addComponent(GroupLa yout.java:1490)
    at javax.swing.GroupLayout$SequentialGroup.addCompone nt(GroupLayout.java
    :1771)
    at javax.swing.GroupLayout$SequentialGroup.addCompone nt(GroupLayout.java
    :1713)
    at javax.swing.GroupLayout$Group.addComponent(GroupLa yout.java:1471)
    at javax.swing.GroupLayout$SequentialGroup.addCompone nt(GroupLayout.java
    :1746)
    at library.<init>(library.java:212)
    at library.main(library.java:518)
    Press any key to continue...
    Now what to do

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. NullPointerException
    By mensa in forum Java 2D
    Replies: 5
    Last Post: 05-03-2008, 11:19 PM
  2. NullPointerException
    By ravian in forum New To Java
    Replies: 2
    Last Post: 12-07-2007, 04:20 PM
  3. NullPointerException
    By Feng in forum New To Java
    Replies: 5
    Last Post: 11-24-2007, 07:51 PM
  4. nullPointerException problem
    By conandor in forum Networking
    Replies: 1
    Last Post: 08-14-2007, 01:22 PM
  5. ERROR: nullPointerException
    By mathias in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 06:54 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
  •