I have a JTextField in my form which i use for book name input. Based on this book's name, I'm trying to pass author's and publisher's values to new JFrame (NewPage) JTextFields (authortxtfield and publishertxtfield). Each time when i execute this code, i get java.lang.NullPointerException. authortxtfield and publishertxtfield are both public. Am i doing something wrong?
public void getBook(){
try {
ps = conn.prepareStatement("SELECT author, publisher FROM books WHERE txtfld_bookname=?");
ps.setString(1, txtfld_bookname.getText());
rs = ps.executeQuery();
while(rs.next())
{
NewPage.authortxtfield.setText(rs.getString("author"));
NewPage.publishertxtfield.setText(rs.getString("publisher"));
}
} catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
I would also like to know if there's a way to concatenate author and publisher into one JTextField so i wouldn't have to use 2.