Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Easy - JTextArea won't get the text? and more stuff is wrong?

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Easy - JTextArea won't get the text? and more stuff is wrong?

    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!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Easy - JTextArea won't get the text? and more stuff is wrong?

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at Pasen.PaasPaneel.JaartalTester(PaasPaneel.java:95)
    There is a variable with a null value at line 95 when it is executed. Look at line 95, find the variable with the null value and then backtrack in the code to see why that variable does not have a valid value.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Re: Easy - JTextArea won't get the text? and more stuff is wrong?

    huh?

    line 94 :

    String einddatum = ("in " + beginJaartal + "valt pasen op de dag " + paasDag + "van maand " + paasMaand); // gives the String "einddatum" a value

    line 95 + 96:

    System.out.println(einddatum);
    uitkomstveld.setText(einddatum); // this should set the value of "uitkomstveld" to "einddatum" but it doesn't work yet.

    in line 94 I gave "einddatum" a value and in line 95 + 96 I said print einddatum and set the text of "uitkomstveld" to "einddatum".
    what variable does not have a value at this point? I don't understand this?

    EDIT: "einddatum" has a variable, if I print it out :

    [in 2007 valt pasen op de dag 8 van maand 4]

    and what's wrong with line 110? :

    JaartalTester(beginJaartal); // calls the method JaartalTester

    I don't understand this and this is very confusing for me :S.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Easy - JTextArea won't get the text? and more stuff is wrong?

    uitkomstveld.setText(einddatum);
    If this is line 95,
    What value does uitkomstveld have?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Easy - JTextArea won't get the text? and more stuff is wrong?

    it doesn't have a value at that point .. I think.. it's a JTextArea. Isn't it normal that it has no value at that point?

    uitkomstveld.setText(einddatum);

    So here I try to set the value of uitkomstveld to "einddatum" but it won't work.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Easy - JTextArea won't get the text? and more stuff is wrong?

    What value does the variable: uitkomstveld have? Print out the variable and see if it has a value.
    You expect it to have the address of a text area. Does it? I think it has a null value and is what is giving the exception. Print it and see.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Jan 2013
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Easy - JTextArea won't get the text? and more stuff is wrong?

    well, the value is null

    how do I fix that? what value do I have to give to a JTextArea ? no idea ..

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Easy - JTextArea won't get the text? and more stuff is wrong?

    what value do I have to give to a JTextArea
    You use the new statement with a constructor to give object reference variables their value.
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    kaskoepoes112 (January 19th, 2013)

  10. #9
    Junior Member
    Join Date
    Jan 2013
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Easy - JTextArea won't get the text? and more stuff is wrong?

    thanks I'm so dumb thank you so much <3

Similar Threads

  1. diplay a large text in JTextArea (>2GB)
    By NeoDesWay in forum AWT / Java Swing
    Replies: 4
    Last Post: August 18th, 2013, 07:20 AM
  2. read text from a JTextArea
    By eiboog in forum AWT / Java Swing
    Replies: 1
    Last Post: November 6th, 2011, 10:37 AM
  3. Trying to display text from file in JTextArea. Please Help.
    By rjdelight in forum Java Theory & Questions
    Replies: 7
    Last Post: June 29th, 2011, 05:10 AM
  4. How can I avoid JTextArea from grabbing focus upon setting text
    By Orit in forum Java Theory & Questions
    Replies: 4
    Last Post: October 4th, 2010, 05:17 AM
  5. How can I append text in JTextArea from another class
    By chikaman in forum AWT / Java Swing
    Replies: 2
    Last Post: December 10th, 2009, 10:26 AM

Tags for this Thread