Results 1 to 4 of 4
Thread: NullPointerException
- 06-10-2008, 08:57 PM #1
Member
- Join Date
- May 2008
- Posts
- 29
- Rep Power
- 0
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.
- 06-11-2008, 03:56 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
One of your member not get the correct value, and set null at run time. Do you have debug and see where it happened?
- 06-11-2008, 07:41 AM #3
Member
- Join Date
- May 2008
- Posts
- 29
- Rep Power
- 0
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
- 06-11-2008, 08:42 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I hope something wrong with GroupLayout.
Similar Threads
-
NullPointerException
By mensa in forum Java 2DReplies: 5Last Post: 05-03-2008, 11:19 PM -
NullPointerException
By ravian in forum New To JavaReplies: 2Last Post: 12-07-2007, 04:20 PM -
NullPointerException
By Feng in forum New To JavaReplies: 5Last Post: 11-24-2007, 07:51 PM -
nullPointerException problem
By conandor in forum NetworkingReplies: 1Last Post: 08-14-2007, 01:22 PM -
ERROR: nullPointerException
By mathias in forum New To JavaReplies: 1Last Post: 08-05-2007, 06:54 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks