This is my first post, I'm having an issue in my application, I'm programing in Java.
I need to implement the observer pattern, because I have a main window and I need to add elements. When I add a element then the main window should be updated. I put the implements and extends Observable and Observer in the right classes and in the main window, I also override the update method. But when the update executes it throws me an exception.
Here is the code and the exeption:
#Override
public void update(Observable o, Object arg) {
// Update Hotels
this.popularHoteles(unDepartamento.getListaHoteles());
}
private void popularHoteles(ArrayList<Hotel> Hoteles) {
listaHoteles.removeAll();
if (fechasCorrectas()) {
listaHoteles.setListData(Hoteles.toArray());
}
}
where "listaHoteles" is a Jlist item on my from.
when i execute the setListDadta i recive this exeption:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at
diaztaranto.interfaces.MenuPrincipal.listaHotelesValueChanged(MenuPrincipal.java:937)
at
diaztaranto.interfaces.MenuPrincipal.access$800(MenuPrincipal.java:20)
at
diaztaranto.interfaces.MenuPrincipal$9.valueChanged(MenuPrincipal.java:345)
at javax.swing.JList.fireSelectionValueChanged(JList.java:1798) at
javax.swing.JList$ListSelectionHandler.valueChanged(JList.java:1812)
at
javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:184)
at
javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:164)
at
javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:211)
at
javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:405)
at
javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:415)
at
javax.swing.DefaultListSelectionModel.removeSelectionIntervalImpl(DefaultListSelectionModel.java:576)
at
javax.swing.DefaultListSelectionModel.clearSelection(DefaultListSelectionModel.java:420)
at javax.swing.JList.clearSelection(JList.java:2045) at
diaztaranto.interfaces.MenuPrincipal.popularHoteles(MenuPrincipal.java:998)
at
diaztaranto.interfaces.MenuPrincipal.update(MenuPrincipal.java:1043)
at java.util.Observable.notifyObservers(Observable.java:159) at
java.util.Observable.notifyObservers(Observable.java:115) at
diaztaranto.dominio.Hotel.agregarComentario(Hotel.java:212) at
diaztaranto.interfaces.Evaluacion.botonEvaluarActionPerformed(Evaluacion.java:135)
at diaztaranto.interfaces.Evaluacion.access$000(Evaluacion.java:6)
at
diaztaranto.interfaces.Evaluacion$1.actionPerformed(Evaluacion.java:56)
at
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at
javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at
javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505) at
javax.swing.JComponent.processMouseEvent(JComponent.java:3321) at
java.awt.Component.processEvent(Component.java:6270) at
java.awt.Container.processEvent(Container.java:2229) at
java.awt.Component.dispatchEventImpl(Component.java:4861) at
java.awt.Container.dispatchEventImpl(Container.java:2287) at
java.awt.Component.dispatchEvent(Component.java:4687) at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at
java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273) at
java.awt.Window.dispatchEventImpl(Window.java:2719) at
java.awt.Component.dispatchEvent(Component.java:4687) at
java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729) at
java.awt.EventQueue.access$200(EventQueue.java:103) at
java.awt.EventQueue$3.run(EventQueue.java:688) at
java.awt.EventQueue$3.run(EventQueue.java:686) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at
java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:702) at
java.awt.EventQueue$4.run(EventQueue.java:700) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:699) at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
any one knows why this is happen?
Thanks in advice!
Related
I am trying to run the following code but it gives me an error
public void addToContainer(JInternalFrame internalframe){
JInternalFrame []allFrames = Jdpmain.getAllFrames();//getting an array of all the frames in my jdesktoppane(jdpmain)
boolean flag=false;
for(int i=0;i<allFrames.length;i++){
JInternalFrame currentFrame = allFrames[i];
if(internalframe.getClass().isInstance(allFrames[i])){
Jdpmain.setSelectedFrame(currentFrame);//if the internal frame already exist it might be under another jinternalframe so, I called this method to bring it to focus
flag=true;
}
if(flag==false){
Jdpmain.add(internalframe); //if an instance of the frame I am adding does not exist in jdesktoppane it should add an instance of it to jdesktoppane
}
}
}
Exception in thread "AWT-EventQueue-0"
java.lang.IllegalArgumentException: illegal component position at
java.awt.Container.addImpl(Container.java:1093) at
javax.swing.JLayeredPane.addImpl(JLayeredPane.java:230) at
javax.swing.JDesktopPane.addImpl(JDesktopPane.java:486) at
java.awt.Container.add(Container.java:410) at
MyLibrarypackage.MainFrame.addToContainer(MainFrame.java:169) at
MyLibrarypackage.MainFrame.jButton2ActionPerformed(MainFrame.java:148)
at MyLibrarypackage.MainFrame.access$100(MainFrame.java:13) at
MyLibrarypackage.MainFrame$2.actionPerformed(MainFrame.java:62) at
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at
javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at
javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505) at
javax.swing.JComponent.processMouseEvent(JComponent.java:3321) at
java.awt.Component.processEvent(Component.java:6270) at
java.awt.Container.processEvent(Container.java:2229) at
java.awt.Component.dispatchEventImpl(Component.java:4861) at
java.awt.Container.dispatchEventImpl(Container.java:2287) at
java.awt.Component.dispatchEvent(Component.java:4687) at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at
java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273) at
java.awt.Window.dispatchEventImpl(Window.java:2713) at
java.awt.Component.dispatchEvent(Component.java:4687) at
java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707) at
java.awt.EventQueue.access$000(EventQueue.java:101) at
java.awt.EventQueue$3.run(EventQueue.java:666) at
java.awt.EventQueue$3.run(EventQueue.java:664) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at
java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680) at
java.awt.EventQueue$4.run(EventQueue.java:678) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677) at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
I will be glad if anyone could help me here.
Here is the code of mouse entered event of label 1 . And the exception is occuring .I have already worked on previous version but I don't why this happening now.
private void jLabel1MouseEntered(java.awt.event.MouseEvent evt) {
ImageIcon n_cig;
n_cig = new ImageIcon(getClass().getResource("masterproject/Cfull.png"));
jLabel1.setIcon(n_cig);
}
private void jLabel1MouseExited(java.awt.event.MouseEvent evt) {
ImageIcon n_cig;
n_cig = new ImageIcon(getClass().getResource("masterproject/No Cigarretes.png"));
jLabel1.setIcon(n_cig);
}
And the exceptions are here
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:205)
at masterproject.design.jButton1ActionPerformed(design.java:384)
at masterproject.design.access$300(design.java:15)
at masterproject.design$3.actionPerformed(design.java:148)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
The reason that you get a NullPointerException is because for some reason the image file that you're trying to specify cannot be located. So the getResource() method returns a null.
Create a utility function to handle these kind of exception in future
public ImageIcon createImageIcon(String path,
String description) {
java.net.URL imgURL = getClass().getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL, description);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
Check using this function that wheather or not you are able to access the image or not
I'm Trying to run this code to get the ResultSet row by row into an Array so i can put them in a jTable. I don't get why i get this error, i'm new in this.
I would be totally thankfull if you could help me.
try {
int pos = 1;
for (int r=0;r<rsCount;r++){
String[] na = null;
res.absolute(pos);
int a=1;
while(res.next()){
na[a]=res.getString(a+1);
a+=1;
}
pos+=1;
for(int c=0;c<8;c++){
tabla.setValueAt(na[c], r, c);
}
}
} catch (SQLException ex) {
Logger.getLogger(Reporte.class.getName()).log(Level.SEVERE, null, ex);
}
}
And here is the OUTPUT:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Main.Reporte.jButton1ActionPerformed(Reporte.java:254)
at Main.Reporte.access$000(Reporte.java:17)
at Main.Reporte$1.actionPerformed(Reporte.java:78)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:702)
at java.awt.EventQueue$4.run(EventQueue.java:700)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Your string array is not being properly instantiated. You need to instantiate it like:
String[] na = new String[100];
If you don't know how big the array is going to be you might want to consider using an ArrayList
ArrayList<String> na = new ArrayList<String>();
then each string can be added with:
na.add(res.getString(a+1));
Good time, everyone. I have a bad issue in my code. When I compile it, it doesn't works like I expected and returns me too many exceptions.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at kazemirdo.KazemirdoMatcher.KazemirdoMatcherAct(KazemirdoMatcher.java:53)
at kazemirdo.KazemirdoGUI$1.actionPerformed(KazemirdoGUI.java:47)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3311)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at kazemirdo.KazemirdoMatcher.KazemirdoMatcherAct(KazemirdoMatcher.java:53)
at kazemirdo.KazemirdoGUI$1.actionPerformed(KazemirdoGUI.java:47)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3311)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
First one at kazemirdo.KazemirdoMatcher.KazemirdoMatcherAct(KazemirdoMatcher.java:53) refers:
public void KazemirdoMatcherAct() {
requestWords = kC.getRequestBuffer();
int j = 0;
// Searchs the matches
for (String match : requestWords) { // Refers right here.
p = Pattern.compile(match + "\t.*");
for (int i = 0; i < morphBuffer.length; i++) {
if (morphBuffer[i] == null) {
buffer[j] = morphBuffer[i+1];
}
else {
m = p.matcher(morphBuffer[i]);
if(m.find()) j++;
}
}
}
}
Second exception refers to place, when I'm calling KazemirdoMatcherAct() method.
But others.. I can't understand, really.
What I do wrong?
Whole code, if needed: http://fpaste.org/62123/18201713/
Maybe you can System.out.print the requestWords in KazemirdoConverter,see what is the String request.
I want to create new thread (for Server). I have textArea where I put my logs, I created a new class status which handles it. I run new thread for object "server", I try to "deliver" my status object to server and there do status.setStatus("blabal"); But there is a problem....
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Server.<init>(Server.java:16)
at Main.MainPanelButtonStartActionPerformed(Main.java:154)
at Main.access$000(Main.java:9)
at Main$1.actionPerformed(Main.java:63)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.JToggleButton$ToggleButtonModel.setPressed(JToggleButton.java:308)
at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Exception in thread "Thread-2" java.lang.NullPointerException
at Server.run(Server.java:23)
at java.lang.Thread.run(Thread.java:722)
BUILD SUCCESSFUL (total time: 3 seconds)
My code:
private void MainPanelButtonStartActionPerformed(java.awt.event.ActionEvent evt) {
if(!serverCreated) {
server = new Server(Integer.parseInt(MainPanelTextPort.getText()));
server.setStatusObj(status);
serverThread = new Thread(server);
//SwingUtilities.invokeLater(serverThread); don't know how to use it correctly
serverThread.start();
MainPanelButtonStart.setText("Stop");
serverCreated = true;
} else {
if(!(serverThread.isInterrupted()))
{
try {
server.getServerSocket().close();
} catch(IOException e) {}
serverThread.interrupt();
MainPanelButtonStart.setText("Start");
serverCreated = false;
}
}
}
The variable status is not instantiated on this line in the Server constructor:
status.setStatus("Server Created.");
Assuming this represents RUNNING, STOPPED, etc. these can be set internally in the Server class as it will be able to determine the run state of the server itself.
Regular Threads do not encapsulate correct interaction with the Event Dispatch Thread. SwingWorker would be a better option here. This post has an example.
Aside: Given Java code conventions, MainPanelTextPort would be represented as mainPanelTextPort.