First of all , I'm new here
My name is Kasper and I'm new at java (want to learn it)
I'm from holland so my english isn't perfect.
so I've created a very basic program which can calculate the Easter date for each year.
this is the clas with the problem ( it's easy for you but for me it is hard (new at java))
package Pasen; import java.awt.event.*; import javax.swing.*; public class PaasPaneel extends JPanel implements ActionListener { private JTextField Jaartalveld; private JButton Bereken; private JTextArea uitkomstveld; int paasMaand; int paasDag; public String einddatum; public PaasPaneel() { JTextField Jaartalveld= new JTextField(4); // just doing basic stuff JButton Bereken = new JButton("Bepaal paasdatum"); Bereken.addActionListener(this); // adds actionlistener to this JButton JTextArea uitkomstveld = new JTextArea(12, 35); add(new JLabel("Jaar")); add(Jaartalveld); add(Bereken); add(uitkomstveld); } /* * This should calculate all the stuff */ public void JaartalTester(int beginJaartal) { System.out.println ("hoi"); if (beginJaartal < 1900 || beginJaartal > 2099 ) // checks if the input is right { JOptionPane.showMessageDialog( // show's this if the input is wrong null, "het jaartal moet tussen 1900 en 2099 zijn", "Onjuist jaartal", JOptionPane.ERROR_MESSAGE); } else { int A = beginJaartal % 19; // more calculation System.out.println(A); // debugging , same as below int B = beginJaartal % 4; System.out.println("dit is 2" + B); int C = beginJaartal % 7; int D = (19 * A + 24) % 30; int E = (5 + 2 * B + 4 * C + 6 * D) % 7; int F = D + E - 9; System.out.println("dit is " +F); // more debugging if (F > 0) { paasMaand = 4; System.out.println("waarde paasMaand = " + paasMaand); if (F == 26) { paasDag = 19; } else { if (F == 25 && D == 28) { paasDag = 18; } else { paasDag = F; System.out.println("hij komt hier"); } } } else { paasMaand = 3; paasDag = F + 31; } } if (! (paasMaand <= 0 || paasDag <= 0)) { einddatum =("in " + beginJaartal + "valt pasen op de dag " + paasDag + "van maand " + paasMaand); // gives the String "einddatum" a value System.out.println(einddatum); uitkomstveld.setText(einddatum); // this should set the value of "uitkomstveld" to "einddatum" but it doesn't work yet. } } public void actionPerformed (ActionEvent e) { int beginJaartal = 2007; //random default value // Integer.parseInt(Jaartalveld.getText()); this should create a String which contains the text of "jaartalveld" but it doesn't work right know. System.out.println("het beginjaartal is " + beginJaartal); //some debugging JaartalTester(beginJaartal); // calls the method JaartalTester } }
when I run this program the console is like this:
het beginjaartal is 2007 hoi Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Pasen.PaasPaneel.JaartalTester(PaasPaneel.java:95) at Pasen.PaasPaneel.actionPerformed(PaasPaneel.java:111) 12 dit is 23 dit is 8 waarde paasMaand = 4 hij komt hier in 2007valt pasen op de dag 8van maand 4 at javax.swing.AbstractButton.fireActionPerformed(Unknown 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.mouseReleased(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(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown 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.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$1.doIntersectionPrivilege(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.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
sorry I'm such a noob >.< but I really don't know what to do..
Hope you can help me !
thanks!