• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How do i call a method that calls a method?

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Person class, a Name class, and a demo. What i need is to call a method from the Person class that calls a method from the Name class for the demo. Heres an example:




 
author & internet detective
Posts: 42134
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Daniel,
Consider changing

to


Java starts variables with lower case letters. Which makes it clearer whether you are using the class Name or the variable name.

You are getting the NullPointer because Person never instantiates name. You want to create a setter in the Person class like public void setName(Name n) { name = n): }. Then your tester class can pass in a Name object.
 
Daniel Hoang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh yeah, i didnt include that in my code example, oops. While i do have a set method, im trying a couple ways shown below, but still get a nullpointer. What else am i missing?



 
Jeanne Boyarsky
author & internet detective
Posts: 42134
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've succeeded in moving the NullPointer to your set method. But Person still doesn't instantiate Name. So it is null when you try to update it in the setter. You need to call new Name() in the Person constructor.
 
Daniel Hoang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont think im allowed to edit the demo
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Hoang wrote:Heres an example:


Daniel,

Please DontWriteLongLines. It makes your threads very hard to read. I've broken your up this time.
Remember the rule: 80 charcters max.

Thanks

Winston
 
reply
    Bookmark Topic Watch Topic
  • New Topic