Pessoal, to começando…
Tentei achar a solução, ate vi no forum que o provavel erro é que tem algo nao inicializado mas na boa nao achei.
o erro é o seguinte:
Exception in thread AWT-EventQueue-0 java.lang.NullPointerException
at findRecord.actionPerformed(findRecord.java:25)
o codigo é esse:
public class agenda extends JFrame{
private Connection dbconn;
private creategui screenvar;
public agenda(){
try {
String url = "jdbc:odbc:BakeryBook";
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
dbconn = DriverManager.getConnection( url );
//msgout.append( "Connection successful\n" );
}
catch ( ClassNotFoundException cnfex ) {
// process ClassNotFoundExceptions here
cnfex.printStackTrace();
//msgout.append( "Connection unsuccessful\n" +
// cnfex.toString() );
}
catch ( SQLException sqlex ) {
// process SQLExceptions here
sqlex.printStackTrace();
//msgout.append( "Connection unsuccessful\n" +
// sqlex.toString() );
}
catch ( Exception excp ) {
// process remaining Exceptions here
excp.printStackTrace();
//msgout.append( excp.toString() );
}
screenvar = new creategui(dbconn);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
agenda ag = new agenda();
}
}
class creategui extends JPanel{
JTextField buscatx;
botao bton;
JFrame frame;
private Connection dbconn;
private creategui creategui;
QueryTableModel qry;
JTable jtbl;
JScrollPane jspane;
public creategui(Connection dbc){
dbconn = dbc;
buscatx = new JTextField(20);
JLabel lbusca = new JLabel("Buscar");
GridBagLayout framegbl = new GridBagLayout();
GridBagLayout gbl = new GridBagLayout();
frame = new JFrame();
JPanel labelpane = new JPanel(gbl);
bton = new botao(dbc,creategui);
qry = new QueryTableModel(dbc,creategui);
qry.query();
jtbl = new JTable( qry );
jspane = new JScrollPane( jtbl );
int row = 0;
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.NONE;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.insets = new Insets(0,5,0,0);
add(labelpane,lbusca,gbl,gbc,0,row,1,1);
row++;
add(labelpane,buscatx,gbl,gbc,0,row,1,1);
gbc.insets = new Insets(0,0,0,0);
//row++;
add(labelpane,bton,gbl,gbc,1,row,1,1);
row++;
add(labelpane,jspane,gbl,gbc,0,row,1,1);
add(frame,labelpane,framegbl,gbc,0,0,1,1);
frame.pack();
frame.setVisible(true);
frame.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
System.exit( 0 );
}
}
);
}
public static void add(
Container container,
Component c,
GridBagLayout gbl,
GridBagConstraints gbc,
int x, int y, int w, int h)
{
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = w;
gbc.gridheight = h;
gbl.setConstraints(c,gbc);
container.add(c);
}
}
class findRecord implements ActionListener {
private creategui screenvar;
private Connection dbconn;
public findRecord( Connection dbc, creategui scv ){
dbconn = dbc;
screenvar = scv;
}
public void actionPerformed( ActionEvent e ){
try{
String numstrg = new String();
//for (int i=0; i < screenvar.buscatx.getText().length();i++){
//numstrg += screenvar.buscatx.getText().substring(i,i+1);
(Linha 25) ------------> numstrg = screenvar.buscatx.getText();
//}// for
if (!numstrg.equals("")){
Statement statement = dbconn.createStatement();
String query = "Select * from Orders";
dbconn.nativeSQL(query);
ResultSet rs = statement.executeQuery( query );
}// if
}// try
catch (SQLException sqlex){
sqlex.printStackTrace();
}// catch
}
}
Valeu