为什么程序抛出了一个NullPointerException?
数据库能正确连接,且数据库中已有一条记录
但在
Statement stmt=conn.createStatement();这一行,程序提示为NullPointerException异常
请高手指教
程序如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;
public class dukecookies extends JFrame {
String title="DukeCookies Demo";
private JTextArea msgout;
private DataPanel screen;
private Connection conn;
//private ButtonPanel btn;
//private BtnGrp btn;
public dukecookies() {
super("Duke Cookies Demo");
setSize(500,500);
Container p = getContentPane();
screen=new DataPanel();
msgout=new JTextArea(8,40);
p.setLayout(new FlowLayout());
p.add(new JScrollPane(screen));
p.add(new JScrollPane(msgout));
ButtonPanel controls=new ButtonPanel(conn,screen,msgout);
p.add(controls);
//p.add(rad);
setVisible(true);
DataBaseConn con=new DataBaseConn();//connect Database
}
class DataPanel extends JPanel {
JTextField id,first,last,address,phone,city,state,zip,country,email,fax;
JLabel lfirst,llast,laddress,lphone,lcity,lstate,lzip,lcountry,lemail,lfax;
public DataPanel() {
JPanel labelPanel=new JPanel();
labelPanel.setLayout(new GridLayout(10,1));
lfirst=new JLabel("First Name:",0);
labelPanel.add(lfirst);
llast=new JLabel("Last Name:",0);
labelPanel.add(llast);
laddress=new JLabel("Address:",0);