my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Exception in thread "AWT-EventQueue-0" " Watch "Exception in thread "AWT-EventQueue-0" " New topic
Author

Exception in thread "AWT-EventQueue-0"

Pradeep
Ranch Hand

Joined: Sep 19, 2006
Posts: 49
hi
i want to do table sorting based on column

i am getting following error :




Sorting ...
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.cisco.dca.TableSorter.checkModel(TableSorter.java:146)
at com.cisco.dca.TableSorter.sort(TableSorter.java:152)
at com.cisco.dca.TableSorter.sortByColumn(TableSorter.java:201)
at com.cisco.dca.TableHeaderSorter.mouseClicked(TableSorter.java:231)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:212)
at java.awt.Component.processMouseEvent(Component.java:5504)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3135)
at java.awt.Component.processEvent(Component.java:5266)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3968)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3901)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1778)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)



my java code is as follows

public class MarkSuspiciousBaggage extends javax.swing.JPanel {

{
//Set Look & Feel
try {
javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch(Exception e) {
e.printStackTrace();
}
}

private JScrollPane scroll;
private JTable table;
private JButton jButton1;
private JLabel details;
private JLabel header;
private JButton locateSuspiciousLuggage;
public static MarkSuspiciousBaggage markSuspiciousBaggageInstance = null;

class ButtonListener implements ActionListener {
JTable tab ;
ButtonListener(JTable table)
{
System.out.print("table is " + table);
this.tab = table;
}
public void actionPerformed(ActionEvent e) {
System.out.println("inside actionPerformed " + e.getActionCommand() + " source " + e.getSource());
if(e.getActionCommand().equals("Clear Tag"))
{
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

try {
DBUtils.loadDriver();
conn = DBUtils.fetchConnection();
System.out.println("before selected");
System.out.println("value is " + tab.getValueAt(0,0 ));

System.out.println("value of the ======= " + tab.getValueAt(tab.getSelectedRow(), 0));
String query = "update DCA_Baggage_Info set ISSuspicious ='N' where TagID = '"+tab.getValueAt(tab.getSelectedRow(), 0)+"'";
stmt = conn.createStatement();
rs = stmt.executeQuery(query);
System.out.println("finshed");
}catch(Exception SQLexp1){
}

//System.out.println("value of the ======= " + tab.getValueAt(tab.getSelectedRow(), 6));


}
else
{
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

try {
DBUtils.loadDriver();
conn = DBUtils.fetchConnection();
System.out.println("before selected");
System.out.println("value is " + tab.getValueAt(0,0 ));

System.out.println("value of the ======= " + tab.getValueAt(tab.getSelectedRow(), 0));
String query = "update DCA_Baggage_Info set ISSuspicious ='Y' where TagID = '"+tab.getValueAt(tab.getSelectedRow(), 0)+"'";
stmt = conn.createStatement();
rs = stmt.executeQuery(query);
System.out.println("finshed");
}catch(Exception SQLexp1){
}
}

}

}
/**
* Auto-generated main method to display this
* JPanel inside a new JFrame.
*/
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new MarkSuspiciousBaggage());
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);

}

private MarkSuspiciousBaggage() {
super();
initGUI();
marksuspiciousBaggagePopulate();
}

public static MarkSuspiciousBaggage getInstance() {

if (markSuspiciousBaggageInstance == null) {
System.out.println("I am here in mark");
markSuspiciousBaggageInstance = new MarkSuspiciousBaggage();
return markSuspiciousBaggageInstance;
} else {
return markSuspiciousBaggageInstance;
}
}

private void initGUI() {
try {
GridBagLayout thisLayout = new GridBagLayout();
thisLayout.rowWeights = new double[] {0.1, 0.1, 0.1};
thisLayout.rowHeights = new int[] {7, 7, 7};
thisLayout.columnWeights = new double[] {0.1};
thisLayout.columnWidths = new int[] {7};
this.setLayout(thisLayout);
this.setPreferredSize(new java.awt.Dimension(772, 531));

scroll = new JScrollPane();
this.add(scroll, new GridBagConstraints(0, 0, 1, 3, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(60, 5, 50, 5), 0, 0));
scroll
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scroll
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setPreferredSize(new Dimension(200, 1000));
scroll.setBorder(new LineBorder(
new java.awt.Color(0, 0, 0),
1,
false));
scroll.setName("BagageSearch_JS_ScrollPane");
scroll.setSize(new Dimension(1000, 1000));

locateSuspiciousLuggage = new JButton();
this.add(locateSuspiciousLuggage, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(55, 10, 10, 0), 0, 0));
locateSuspiciousLuggage.setText("Tag Suspicious");

header = new JLabel();
this.add(header, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
header.setText("Mark Suspicious Luggage");
header.setSize(400, 20);
header.setFont(new java.awt.Font("Tahoma",1,14));
header.setForeground(new java.awt.Color(128,0,0));
header.setHorizontalAlignment(SwingConstants.CENTER);

details = new JLabel();
this.add(details, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 10, 55, 0), 0, 0));
details.setText("List of all the Tagged Baggage's:");

jButton1 = new JButton();
this.add(jButton1, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.SOUTH, GridBagConstraints.NONE, new Insets(55, 10, 10, 0), 0, 0));
jButton1.setText("Clear Tag");

} catch (Exception e) {
e.printStackTrace();
}
}
public void marksuspiciousBaggagePopulate() {
System.out.println("***********************************************************");
System.out.println("Within populate ########### ");
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

try {
DBUtils.loadDriver();
conn = DBUtils.fetchConnection();
String countquery = "select count(*) from DCA_PASSENGER_INFO";
int rowcount = 0;
stmt = conn.createStatement();
rs = stmt.executeQuery(countquery);
while (rs.next()){
rowcount = rs.getInt(1);
}

stmt.close();
rs.close();

//String queryString = "select PassengerID,TagID,PASSENGER_NAME,FLIGHT_NO,TICKET_NUMBER,SEAT_NUMBER from DCA_PASSENGER_INFO";
String queryString = "SELECT bi.TagID, fd.*, pi.* FROM DCA_Baggage_Info bi,DCA_PASSENGER_INFO pi,DCA_Flight_Details fd WHERE pi.PassengerID=bi.Passenger_Id and pi.FLIGHT_NO = fd.FLIGHT_NO";
stmt = conn.createStatement();
System.out.println("Query Details >>>>> " + queryString);
rs = stmt.executeQuery(queryString);

int li_row = 0;

Object [][] addVal = new Object[rowcount][7];
Object baggageid = null;
Object flightnumber = null;
Object ticketnumber = null;
Object passengername = null;
Object airlinecode = null;
Object dateofjourney = null;
ButtonGroup group1 = new ButtonGroup();
while (rs.next()) {
baggageid = rs.getString("TagID");
flightnumber = rs.getString("FLIGHT_NO");
ticketnumber = rs.getString("TICKET_NUMBER");
passengername = rs.getString("PASSENGER_NAME");
airlinecode = rs.getString("AirLine_Code");
dateofjourney = rs.getString("departure_time");

addVal[li_row][0] = baggageid;
addVal[li_row][1] = flightnumber;
addVal[li_row][2] = ticketnumber;
addVal[li_row][3] = passengername;
addVal[li_row][4] = airlinecode;
addVal[li_row][5] = dateofjourney;
JRadioButton radioButton = new JRadioButton();
group1.add(radioButton);
addVal[li_row][6] = radioButton;
li_row ++;
}
DefaultTableModel dm = new DefaultTableModel();
dm.setDataVector(addVal, new Object[] { "BaggageID", "Flight_No", "Ticket_No", "Passanger Name", "AIRLINE CODE", "Date_of_Journey", "Select" });
JTable table = new JTable(dm) {

public boolean isCellEditable(int rowIndex, int vColIndex) {
System.out.println(vColIndex);
if(vColIndex == 6)
return true;
else
return false;
}

public void tableChanged(TableModelEvent e) {
super.tableChanged(e);
System.out.println("inside the event trigred");
repaint();
}
};

TableSorter sortedModel = new TableSorter();
sortedModel.addTableModelListener(table);
// table.setModel(dm);
System.out.println("in table sorting");
TableHeaderSorter.install(sortedModel, table);
System.out.println("i am in table sorter");
table.getTableHeader().setBounds(0, 0, 455, 21);
table.setColumnSelectionAllowed(false);
table.setRowSelectionAllowed(false);
table.setCellSelectionEnabled(false);
table.getColumn("Select").setCellRenderer(
new RadioButtonRenderer());
table.getColumn("Select").setCellEditor(
new RadioButtonEditor(new JCheckBox()));
scroll.setViewportView(table);

ButtonListener b1 = new ButtonListener(table);
locateSuspiciousLuggage.addActionListener(b1);
jButton1.addActionListener(new ButtonListener(table));
System.out.println("End of populate method");

}
catch(Exception SQLexp){
SQLexp.printStackTrace();
System.out.println("Exception while interacting with the database " + SQLexp);
} finally {
DBUtils.closeConnection(conn);
try {
stmt.close();
rs.close();
} catch(Exception e) {
e.printStackTrace();
}

}

}



}
 
jQuery in Action, 2nd edition
 
subject: Exception in thread "AWT-EventQueue-0"
 
Similar Threads
What is error?
updating database cause error
Jtable and database results
Help with getting the database to take values (Java-MySQL)
linking between applet pages