Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    14
    Rep Power
    0
    How would I print out the value of Gooey() or of a JTextArea?
  2. #17
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    I'm not sure why you're interested in those items. Neither of them are variables.
    The NPE is on line 65. You need to look at the variables on line 65 and find which one has a null value. Print it with something like this:
    Code:
    System.out.println("an ID "+ <theVarNameHere>);
    Last edited by NormR; December 4th, 2012 at 02:35 PM.
  4. #18
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    14
    Rep Power
    0
    There really arent any variables, line 65 points to a method that calls setText but I did find that when I am trying to reference the instance of my Gooey that it is null. What is the proper way to reference an instance of another class? I think that is where my problem lies.
  6. #19
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    There really arent any variables
    Post the contents of line 65 if you need help finding the variable(s) used on that line.

    proper way to reference an instance of another class
    By getting the address of the instance into a variable. The first reference will be returned by a new statement.
  8. #20
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    14
    Rep Power
    0
    If you look at my previous post, line 65 is:

    Code:
    testClass.setEventText();

    Which is:
    Code:
    public void setEventText()
    	{
    		textArea.setText("test");
    	}
    testClass is null here. So I think I need to figure out how to properly reference the instance of testClass(which is instantiated in another class).
  10. #21
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    the variable: testClass needs to have the address of an instance of the class: HelloWorldApp2. If an instance of the class already exists, then a reference tot the class should be passed in an arg to the class where its value is needed and saved there in a class variable.
    If there isn't an instance of the class, then use a new statement to create the instance and get its address.
    Last edited by NormR; December 4th, 2012 at 03:16 PM.
  12. #22
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    14
    Rep Power
    0
    Could you show me an example. I understand the logic but I'm having trouble with the syntax(or doing it properly I suppose). I can not create a new instance so I need to reference the instance that was created in the other class, but I'm unsure of how to do this. How would you reference the instance testClass from another class?
  14. #23
  15. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    reference the instance that was created in the other class
    Use the this variable to refer to the current class that the code is executing in.
    Pass a reference:
    Code:
     refToAnotherClass.passRef(this);  // pass a reference to this instance
  16. #24
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    14
    Rep Power
    0
    I didn't really understand the example but after hours of testing I finally am able to get things working correctly. Thanks for the help! (btw it was the null reference to my Gooey instance that was throwing the error )
  18. #25
  19. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    Glad you got it working.
    it was the null reference to my Gooey instance that was throwing the error
    Strange, I don't see any variables that hold a reference to an instance of the Gooey class.
    Last edited by NormR; December 4th, 2012 at 03:58 PM.
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo