Hi guys
I'm having a bit problem with my for-loop, and would just want to hear if i'm way of, or if there is something small i'm missing.
String[] days = {"Monday", "Tuesday", "Wednesday", "Turshday", "Friday", "Saturday", "Sunday"}; String opgType = arbejdsOpgaver.opgTypeText.getText(); String opgave = arbejdsOpgaver.opgText.getText(); String dag = arbejdsOpgaver.opgDagText.getText(); String kunde = arbejdsOpgaver.opgKundeText.getText(); boolean opgCheck = false; if (!opgave.equals("") && opgave.charAt(0) != ' ') { if (!dag.equals("") && dag.charAt(0) != ' ') { if (!kunde.equals("") && kunde.charAt(0) != ' ') { opgCheck = true; } } } if (opgCheck == true) { try { String day = null; for (int i=0; i<= days.length; i++) { day.equals(day + days[i]); if (!day.equals(days)) { opgCheck = false; } } }catch (Exception ee) { System.out.println(ee); } }
I want the for-loop to run through the array, and if the entered day doesn't match one of the days in the array, make the check = false.
At the moment it obviously doesn't work because i'm getting an exception:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at ajRengøring.logic.createOpgave.actionPerformed(cre ateOpgave.java:32)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)