Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Variable value not being carried

 
Robin Heard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really strange problem:



I have checked that 'temp' carries the correct value. However, no matter which method I use to set the variable it doesn't seem to stick. When I call the validate() function the value is NULL even though it has been set before.

The validate() function just some some validation on the variable 'suppliedInput'

Any ideas would be greatly appreciated.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does validate() look like?
 
Robin Heard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some simple length checking on the value that is set previously:




However, when the method is run the value is NULL.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robin Heard wrote:Some simple length checking on the value that is set previously:




However, when the method is run the value is NULL.


What value is null?

Show the entire method body, and signature.

Put in print statements to show i, additionalDetailValidations.get(i), and additionalDetailValidations.get(i).additionalDetailValidationValue).

It's very hard to debug something that's shown in incomplete pieces, rather than an SSCCE.
 
Robin Heard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The 'order' object is the same for both. Could it be to do with the fact that getAllItems() returns an array and then getAdditionalRequirementsType() also returns an array and I'm setting a value within that. It seems like the 'order' object isn't holding the variable the next time it is accessed.
 
Tony Docherty
Bartender
Posts: 2969
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please supply the information Jeff has already asked for.

Could it be to do with the fact that getAllItems() returns an array and then getAdditionalRequirementsType() also returns an array and I'm setting a value within that

They can't be returning arrays or you would have [] to access an element in the array, I guess they are returning ArrayLists.

Add the following line to the line directly after the one where you set suppliedInput = temp and tell us what the output is.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've got too much going on on one line, you're not printing out intermediate values, and I still don't see an SSCCE or the body of the validation method. In short, you're not making it easy for anybody to help you.
 
Robin Heard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator






[Server:server-one] 05:39:10,424 INFO [stdout] (http--0.0.0.0-80-5) Retrieving request parameter for 0: 123456789123456789123211231
[Server:server-one] 05:39:10,454 INFO [stdout] (http--0.0.0.0-80-5) In: 123456789123456789123211231
[Server:server-one] 05:39:10,455 INFO [stdout] (http--0.0.0.0-80-5) Out: 123456789123456789123211231
[Server:server-one] 05:39:10,528 INFO [stdout] (http--0.0.0.0-80-5) temp = 123456789123456789123211231, supplied Input 0 = null
[Server:server-one] 05:39:10,572 INFO [stdout] (http--0.0.0.0-80-5) Is: null but should: 20


 
Tony Docherty
Bartender
Posts: 2969
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try changing:


to

 
Robin Heard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem that would give me is that the value is not maintained in the 'order' object which is saved to a session.
 
Robin Heard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does work though when I change the code. Why does it not remember the variable being set when setting the value in the 'order' object?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is that somewhere in this mess:

You create new AdditionalDetail instances - i.e. each time order.getAllItems().get(i).getAdditionalRequirementsType(order.getrequestType()).get(t) gets called, given the same order, i, and t a new and unique AdditionalDetail object is created (probably a whole new list of them) and the created objects are never stored or reused. So each time you call that method the suppliedInput would be completely different. But that is a guess because you never do what Jeff asks you to do.
 
Robin Heard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve, getAdditionalRequirementsType() was reading from the DB and overwriting the value.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic