Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Apache POI: Unexpected behaviour from if statements

 
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm creating a xlsx worksheet from the data in my javaprogram, but the output isn't as expected, the reasson for it is unknown to me, but it's a couple of if statements that causing it, so hopefully someone of you can tell me why.

My code:

I left out a couple of methods since they're inrelevant to the issue;

This how it looks without the if's:


When I uncomment the first if:

As you can see the name and the period have shifted from the second datacolumn to the first overwritting what was there before.

When I uncomment the second too:

That seems fine, but it should be actually be the first datacolumn (which is the second in my sheet) that's bold. When if follow that logic and change my if statement to && columnCount == 0, it's still the second column that's bold, but now it moved to the first overwritting the data in the first.

Final if statement:

The final if statement which should put the last two lines in a smaller font and bold, causes the lines not to show up at all

I use the same logic on my first worksheet and there it works great, being only with a single if statement, the first one:
 
Saloon Keeper
Posts: 5809
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "unexpected behavior"? Which if statements do or do not evaluate according to your expectations? If they're unexpected, have you dissected the individual clauses of the statements to see whether they have the values you are expecting them to have? If not, start with that.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything that's commented out in setDataDetailSheet, but it might actually not be the if's, but the changeStyme method that's not doing what it's expected, since the if's are being executed when they suposed to...
 
Tim Moores
Saloon Keeper
Posts: 5809
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what have you done to debug it? Have you printed out all the values that are involved in the if statements? Do they have the values that you think they should have?
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As shown on the screenshot, the values are all there, except for when I use the last if statement, it's the styling that's wrong.
There's nothing wrong with the code, the problem is with my logic, which is way harder to solve
 
Sheriff
Posts: 6268
167
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the code you posted, there is a brace missing:
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isnt missing. I places my comments a lign to high and removes it, hends the empty line where the bracket suposed to be
 
Rancher
Posts: 4271
47
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:As shown on the screenshot, the values are all there, except for when I use the last if statement, it's the styling that's wrong.
There's nothing wrong with the code, the problem is with my logic, which is way harder to solve



I think Tim was meaning (and if he wasn't, it's what I would need) is that you need to debug your code, rather than simply looking at the final output.
What values are being used in the areas of the code you think are causing the issue?
Print them out, don't rely on "knowing" what they are.

Also, stick debug notes in there so you can see exactly what route through the code is being taken.
 
Tim Moores
Saloon Keeper
Posts: 5809
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, that's what I meant :-)
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's more important to know which column is being used, not which values, but I get your point...
 
Dave Tolls
Rancher
Posts: 4271
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:I think it's more important to know which column is being used, not which values, but I get your point...



That's one of the values, though.

We're not talking the values in the cells (well, not solely the values in the cells).
We're talking the values in your variables in the Java code, along with what exact path and order your code is taking when it is run and produces the output you are saying is incorrect.

Without knowing those values you cannot say with any certainty what is happening in your code.
You might think you know from just reading the code, but that is very (very) error prone.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for the first two issues (the name and the period that moved to the left) I figured out what the problem is...
For some reason on the two cels before being the street name and phone nr the if condition is executed, changing the style and returning to the beginning of the loop cause of the continue, add the beginning of the loop the columncount is set to 0 resulting in the value being placed in the first column not the second one.
For the wrong column being maded bold, I should check if the columncount is 0, not 1, remeber that I said when I change the condition my second column moves to the left, that's that continue again...
So I need to find a way to make sure that the rest of the if's not being executed without using continue and I also need to find out why on the street and the phonenumber the if is being executed even if the condition isn't met
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So thanks for the tip Dave and Tim, I should debug a bit more before asking questions, it would allow me to ask more specific questions and come easier to a solution...
 
Paper beats rock. Scissors beats tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!