File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes [SOLVED]Method in subclass returns empty when property is used as parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "[SOLVED]Method in subclass returns empty when property is used as parameter" Watch "[SOLVED]Method in subclass returns empty when property is used as parameter" New topic
Author

[SOLVED]Method in subclass returns empty when property is used as parameter

J. Frederik
Greenhorn

Joined: Mar 06, 2013
Posts: 16
when I call getDeliveryFees() it returns empty. When I replace in line 16 "getDistance()" by "1" it works, also in the line before the correct values were output, so I guess I am missing something very basic.

Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7492
    
  18

J. Frederik wrote:so I guess I am missing something very basic.

I think so. You're relying on method chaining too much.

What does getDeliveryFees() return? Why not just run that and check if what it returns is empty before you try using it?

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
J. Frederik
Greenhorn

Joined: Mar 06, 2013
Posts: 16
Thanks for your reply.
lOrderValuesAndDeliveryFees.getDeliveryFees() returns a List of Objects. And yes it does return empty. BUT it does not when I use "new BigDecimal(1)" as parameter instead of "new BigDecimal(getDistance())". As getDistance returns a fine value as I can see by log.debug-message, I guess I am trying to access something in at a stage where it's not fully created or so?

OK, sorry: The Problem is not the exception, but that lOrderValuesAndDeliveryFees.getDeliveryFees() returns empty...
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7492
    
  18

J. Frederik wrote:OK, sorry: The Problem is not the exception, but that lOrderValuesAndDeliveryFees.getDeliveryFees() returns empty...

Right, and printMinimalOrderValue() assumes that what it's getting is NOT empty, which in this case, is plainly wrong.

My advice: write that method so that it can handle an empty List, even if you simply throw an Exception if it happens.

Winston

PS: Please don't edit posts after you've asked a question. It makes things very difficult to follow.

PPS: Welcome to JavaRanch.
J. Frederik
Greenhorn

Joined: Mar 06, 2013
Posts: 16
Ah, sorry for editing...
And thank you for your help.
Problem solved. Point: Stupidity.
I thought I must miss something else because I thought
...it does return empty. BUT it does not when I use "new BigDecimal(1)" as parameter instead of "new BigDecimal(getDistance())". As getDistance returns a fine value...

Now I realised the value of getDistance() was not fine at all. It represented meters and lOrderValuesAndDeliveryFees.getDeliveryFees(BigDecimal distance) is supposed to work with kilometers. There simply was no value for this big km...

So again, thank you!
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7492
    
  18

J. Frederik wrote:Now I realised the value of getDistance() was not fine at all. It represented meters and lOrderValuesAndDeliveryFees.getDeliveryFees(BigDecimal distance) is supposed to work with kilometers. There simply was no value for this big km...

I still suggest you rewrite printMinimalOrderValue() so that it can handle an empty List; otherwise you'll always be dealing with cryptic errors if it ever happens again.

So again, thank you!

You're most welcome.

Winston
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [SOLVED]Method in subclass returns empty when property is used as parameter
 
Similar Threads
Bad design to have JavaBeans with many attributes?
Desperately need help writing Tester
OVERWRITING OBJECTS IN AN ARRAY LIST HELP PLEASE
Intersection points not being determined accurately- java awt
July Newsletter Puzzle (Maze Solver)