File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
J. Frederik
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9470
49
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
J. Frederik
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9470
49
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9470
49
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic