I have JTable
and I want to set value at specific cell from another frame. When I try to do it, I get null pointer exception. I changed the modifiers and removed the exception, but still can't set the value.
Please guys help
public ChequeVoucher(int id,int row){
try {
String str = get_bank_name(id);
System.out.println(str);
table.getModel().setValueAt(str,row,5);
table.getModel().setValueAt(id,row,4);
} catch (SQLException f) {
}
setBank(id,row);
}
public void setBank(int id,int row){
try {
String str = get_bank_name(id);
table.getModel().setValueAt(str,row,5);
} catch (SQLException f) {
}
}
The chequevoucher is my constructor and this piece of code is good until this
table.getModel().setValueAt(str,row,5);
and the JFrame
I get the value from is
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int row = table.getSelectedRow();
int col = table.getSelectedColumn();
String str_id = (String)GetID(row,0);
int id = Integer.parseInt(str_id);
ChequeVoucher CV = new ChequeVoucher(id,row);
setVisible(false);
}
});
The access modifiers wasn't static so I get the following error stack
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at client.ChequeVoucher.(ChequeVoucher.java:215) at client.popupBanks$3.mouseClicked(popupBanks.java:130) at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253) at java.awt.Component.processMouseEvent(Component.java:6292) at javax.swing.JComponent.processMouseEvent(JComponent.java:3267) at java.awt.Component.processEvent(Component.java:6054) at java.awt.Container.processEvent(Container.java:2041) at java.awt.Component.dispatchEventImpl(Component.java:4652) at java.awt.Container.dispatchEventImpl(Container.java:2099) at java.awt.Component.dispatchEvent(Component.java:4482) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168) at java.awt.Container.dispatchEventImpl(Container.java:2085) at java.awt.Window.dispatchEventImpl(Window.java:2478) at java.awt.Component.dispatchEvent(Component.java:4482) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644) at java.awt.EventQueue.access$000(EventQueue.java:85) at java.awt.EventQueue$1.run(EventQueue.java:603) at java.awt.EventQueue$1.run(EventQueue.java:601) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98) at java.awt.EventQueue$2.run(EventQueue.java:617) at java.awt.EventQueue$2.run(EventQueue.java:615) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) at java.awt.EventQueue.dispatchEvent(EventQueue.java:614) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
When I made the modifiers static, I get no exceptions but nothing happens and I can't listen to the JTable
anymore
case KeyEvent.VK_F5:
switch(col){
case 4:
//show the banks
popupBanks pB = new popupBanks(row);
pB.setVisible(true);
break;
}
Sorry for the previous unclear post