Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String not passing to class that extends Activity

 
Tom Mordon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

My classes are calculating and doing the math properly but when I try to pass a string answer to the main class Assignment2Activity.java it show up as null. I'm conducting system.out.println line throughout the project to confirm that my answers are showing up and are correct but when I try to pass the string to the class that extends Activity it fails. But if I try to pass the string to the driver or calculations class it works fine. Any thoughts? I created a getAnswerPassed() and getAnswerToPass in the TimeDifferenceDriver and TimeDifference classes to see if that would change anything and it still shows up as null in the Assignment2Activity class. I've been looking up info on the web and it seems that by extending activity it makes things more difficult, is that true? Any help is appreciated. Thanks








 
Mario Alcantara
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem is not with the class that extends Activity, you have a basic logic problem, in the method getAnswerPassed() of the class TimeDifferenceDriver you are creating an object of type TimeDifference and all properties or instance variables are initialized to default value and a default value of String is null. Once created the object TimeDifference you immediately call method getAnswerToPass() and you get null.

I hope help you and sorry by my english
 
Tom Mordon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you that was pretty much it. I combined the TimeDifference.java and TimeDifferenceDriver.java into the Calculations.java class. Originally I thought the classes were getting too large but the teacher says compared to a real word development environment they were tiny. Also Mario your English was fine.
Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic