|
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.
|