It doesn't get there, the first line of my test program is Workbook wb = new
XSSFWorkbook(); It fails there throwing a NulPointerException. My final code
(which works for me) is:
try {
copyRow(sh, n1, n2);
sh.removeRow(sh.getRow(n1));
copyRow(sh, n2+1, n1);
sh.removeRow(sh.getRow(n2+1));
if (n2+2 <= sh.getLastRowNum()) {
sh.shiftRows(n2+2, sh.getLastRowNum(), -1);
}
} catch (Exception e) {
e.printStackTrace();
}
-----Original Message-----
From: Javen O'Neal [mailto:[email protected]]
Sent: Wednesday, September 23, 2015 2:53 PM
To: POI Users List
Subject: Re: Strange behavior when Math.min() in code
Math.min/StrictMath.min versus your ternary computation look equivalent to me.
What is the value of last just before sh.shiftRows if you use Math.min,
StrictMath.min, or the ternary operator?
On a side-note, I've submitted an implementation of copyRows in bug
58348 (https://bz.apache.org/bugzilla/show_bug.cgi?id=58348).
Javen O'Neal
On Wed, Sep 23, 2015 at 5:59 AM, Murphy, Mark <[email protected]> wrote:
> POI 3.12 - Windows - IBM JVM
>
> Here is some code (CopyRow is my own concoction based on some code I found on
> StackOverflow):
>
> try {
> copyRow(sh, n1, n2);
> sh.removeRow(sh.getRow(n1));
> copyRow(sh, n2+1, n1);
> sh.removeRow(sh.getRow(n2+1));
> // int last = Math.min(sh.getLastRowNum(), n2+2);
> // int last = StrictMath.min(sh.getLastRowNum(), n2+2);
> int last = sh.getLastRowNum();
> last = (last < n2+2 ? n2+2 : last);
> sh.shiftRows(n2+2, last, -1);
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> If I comment out
>
> int last = sh.getLastRowNum();
> last = (last < n2+2 ? n2+2 : last);
>
> and restore either of the two lines above it,
>
> Workbook wb = new XSSFWorkbook();
>
> In my main method (different class) throws a NullPointerException, but the
> code as stated above works, but even so, the logic is incorrect because I was
> confused about what was happening. Now that my fog is clearing, I know how to
> fix the logic, but still remain unclear why Math.min() would cause new
> XSSFWorkbook() to throw a NullPointerError. Any ideas?
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional
commands, e-mail: [email protected]