"AWT-EventQueue-0" java.lang.NullpointerException

i keep getting this at ExsysGui.actionperformed (ExsysGUI.java:78)

i dun understand why it say i send "null" there?

can someone help? thanks in advance

-

publicclass Exsys

{

publicstaticvoid main(String args[])

{

new ExsysGUI("Internet Connection Sharing Trouble Shooter");

}

}

publicclass Cont{

privateint rr;

public Cont(int name)

{rr = name;

}

publicint getrr()

{

return rr;

}

}

--

import java.sql.*;

import java.lang.*;

publicclass esys

{

private String a =new String();

privateint x;

private Connection conn;

private ResultSet rs;

private Statement stat;

public esys(int name)

{

x = name;

try

{

Class.forName("com.mysql.jdbc.Driver");

conn = DriverManager.getConnection("jdbc:mysql://localhost/esys","root","weijie888");

stat = conn.createStatement();

rs = stat.executeQuery("SELECT QUESANS FROM esys WHERE ID = '" + x +"' ");

while(rs.next()){

a = rs.getString("QUESANS");

}

}

catch (SQLException sql)

{

sql.printStackTrace();

}

catch (ClassNotFoundException c)

{

c.printStackTrace();

}

}

public String geta(){

return a;

}

}

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.lang.*;

publicclass ExsysGUIextends JFrame

implements ActionListener

{

private JTextArea display;

private JButton Start;

private JButton yes;

private JButton no;

private JButton how;

private JButton why;

private esys esys;

Cont yy;

private Yes hh;

private No cc;

private How ww;

private Why ee;

public ExsysGUI(String title)

{

setTitle(title);

buildGUI();

pack();

setSize(600,400);

setVisible(true);

}

privatevoid buildGUI()

{ Container contentPane = getContentPane();

contentPane.setLayout(new BorderLayout());

display =new JTextArea(20,70);

display.setFont (new Font("Monospaced", Font.BOLD, 12));

display.setBackground(new Color(0xe0e0e0));

display.setEditable(false);

Start =new JButton("START");

Start.addActionListener(this);

yes =new JButton("YES");

yes.addActionListener(this);

no =new JButton("NO");

no.addActionListener(this);

how =new JButton("HOW");

how.addActionListener(this);

why =new JButton("WHY");

why.addActionListener(this);

JPanel inputPanel =new JPanel();

inputPanel.add(Start);

inputPanel.add(yes);

inputPanel.add(no);

inputPanel.add(how);

inputPanel.add(why);

contentPane.add("Center", display);

contentPane.add("South", inputPanel);

}

publicvoid actionPerformed(ActionEvent e)

{

if (e.getSource() == Start)

{

int name = 1;

esys a =new esys(name);

Cont yy =new Cont(name);

display.append(a.geta() +"\n");

}

if (e.getSource() == yes)

{

int acquireid = yy.getrr();

Yes hh =new Yes(acquireid);

display.append(hh.getyes() +"\n");

}

if (e.getSource() == no)

{

int acquireid = yy.getrr();

No cc =new No(acquireid);

display.append(cc.getno() +"\n");

}

if (e.getSource() == how)

{

int acquireid = yy.getrr();

How ww =new How(acquireid);

display.append(ww.gethow()+"\n");

}

if (e.getSource() == why)

{

int acquireid = yy.getrr();

Why ee =new Why(acquireid);

display.append(ee.getwhy()+"\n");

}

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

import java.sql.*;

import java.lang.*;

publicclass Yes

{

private String yes =new String();

privateint yesID = 0;

privateint x;

private Connection conn;

private ResultSet rs;

private Statement stat;

public Yes(int ID)

{

x = ID;

try

{

Class.forName("com.mysql.jdbc.Driver");

conn = DriverManager.getConnection("jdbc:mysql://localhost/esys","root","weijie888");

stat = conn.createStatement();

rs = stat.executeQuery("SELECT ID , QUESANS FROM esys WHERE YES = '" + x +"' ");

while(rs.next()){

yes = rs.getString("QUESANS");

yesID = Integer.parseInt(rs.getString("ID"));

}

}

catch (SQLException sql)

{

sql.printStackTrace();

}

catch (ClassNotFoundException c)

{

c.printStackTrace();

}

}

Cont update =new Cont(yesID);

public String getyes(){

return yes;

}

}

-

import java.sql.*;

import java.lang.*;

publicclass No

{

private String no =new String();

privateint noID = 0;

privateint x;

private Connection conn;

private ResultSet rs;

private Statement stat;

public No(int noID)

{

x = noID;

try

{

Class.forName("com.mysql.jdbc.Driver");

conn = DriverManager.getConnection("jdbc:mysql://localhost/esys","root","weijie888");

stat = conn.createStatement();

rs = stat.executeQuery("SELECT ID , QUESANS FROM esys WHERE NO = '" + x +"' ");

while(rs.next()){

no = rs.getString("QUESANS");

noID = Integer.parseInt(rs.getString("ID"));

}

}

catch (SQLException sql)

{

sql.printStackTrace();

}

catch (ClassNotFoundException c)

{

c.printStackTrace();

}

}

Cont update =new Cont(noID);

public String getno(){

return no;

}

}

[13171 byte] By [progfreaka] at [2007-10-3 2:58:54]
# 1

Don't use "new String".

private String a = new String();

should be:

private String a = "";

(several other places, too).

It would help if you told us which line was #78. You posted quite a bit of code. Most people here won't count the lines to figure out which one is Line 78.

In actionPerformed, use "if...else if...else if..."--only one of those 'if' statements will be true at any one time.

MLRona at 2007-7-14 20:48:28 > top of Java-index,Java Essentials,New To Java...
# 2
That would happen whenver you click any button other than start in the beginning.the variable yy is not initialized unless you click start button.
PMJaina at 2007-7-14 20:48:28 > top of Java-index,Java Essentials,New To Java...
# 3

if (e.getSource() == yes)

{

int acquireid = yy.getrr();

Yes hh = new Yes(acquireid);

display.append(hh.getyes() + "\n");

int acquireid=yy.getrr();

and the other line the involved this statement....i did make a connection between Temp.java and this file...but it still can't work

progfreaka at 2007-7-14 20:48:28 > top of Java-index,Java Essentials,New To Java...
# 4
yup...the problem right after the start button
progfreaka at 2007-7-14 20:48:28 > top of Java-index,Java Essentials,New To Java...
# 5

This line here (within the actionPerformed method for processing Start):

Cont yy = new Cont(name); // DECLARES LOCAL VARIABLE

should be:

yy = new Cont(name);

With the code you have, you create a local yy, but the yy within the class is still null. The same is true for the other variables you initialize within actionPerformed (those might work, if you don't really need to keep instances of esys, Yes, No, etc. around--if you don't need to keep instances, delete the private variables).

MLRona at 2007-7-14 20:48:28 > top of Java-index,Java Essentials,New To Java...
# 6
thanks....but it is not excatly working yet...i will try somemore...thanks
progfreaka at 2007-7-14 20:48:28 > top of Java-index,Java Essentials,New To Java...
# 7
keep all buttons except for start button as disabled initially andenable all other buttons only after start is clicked
PMJaina at 2007-7-14 20:48:28 > top of Java-index,Java Essentials,New To Java...