Hi, With a random sample xls I do not see the NullPointerException.
Can you also share the XLS file that is triggering this? Or even better a self-contained unit-test that does not require one to adjust the code to make it compile? Also the full stacktrace of the exception would help in finding a possible cause. Thanks... Dominik. On Wed, Sep 3, 2014 at 5:04 PM, kgtokm <[email protected]> wrote: > Hi Adrian Lynch , > > I posted the below code from the site and I wasn't sure you have received it > or not so I am sending it again > > Below is my code for fetching and deleting all the tabs that are not required. > > Workbook wb=null; > Sheet sheet=null; > for (int a = 0; a < sheetCount; a++) { > inStream = new FileInputStream(txtFile.getText().trim()); > > if(txtFile.getText().trim().substring(txtFile.getText().trim().indexOf(".") + > 1).equalsIgnoreCase("xls")) > wb = new HSSFWorkbook(inStream); > else > wb = new XSSFWorkbook(inStream); > workingSheetName = wb.getSheetName(a); > > //get all other tabs to delete > for (int b = 0; b < wb.getNumberOfSheets(); b++) { > if > (!wb.getSheetName(b).trim().equalsIgnoreCase(workingSheetName.trim())) > tabsToDelete.add(wb.getSheetName(b)); > } > > //now delete those tabs > for (int c = 0; c < tabsToDelete.size(); c++) { > if (tabsToDelete.get(c) != null) > wb.removeSheetAt(wb.getSheetIndex((String) > tabsToDelete.get(c))); //This is where my application fails > } > } > > > From: Adrian Lynch [via Apache POI] > [mailto:[email protected]] > Sent: Friday, August 29, 2014 6:21 PM > To: Kranthi Garneni > Subject: Re: POI 3.11 NullPointerException when doing removeSheetAT() for > .xls file > > Show us your code. It's hard to even suggest what might be the issue > without some code to look over. > > A > > > On 29 August 2014 22:09, kgtokm <[hidden > email]</user/SendEmail.jtp?type=node&node=5716488&i=0>> wrote: > >> Hi, >> >> My .xls workbook contains several sheets and when removing sheet using >> removeSheetAt(index) method it throws NullPointerException. >> >> For eg if I have have 3 sheets in my workboox and if I remove 3nd and then >> 2nd sheet it works fine but if I remove 1st sheet or 2nd sheet by keeping >> 3rd sheet then it throws NullPointerException >> >> Iam using poi 3.11 version >> >> Any help would be appreciated. >> >> Thanks in advance >> >> >> >> -- >> View this message in context: >> http://apache-poi.1045710.n5.nabble.com/POI-3-11-NullPointerException-when-doing-removeSheetAT-for-xls-file-tp5716487.html >> Sent from the POI - User mailing list archive at Nabble.com. >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [hidden >> email]</user/SendEmail.jtp?type=node&node=5716488&i=1> >> For additional commands, e-mail: [hidden >> email]</user/SendEmail.jtp?type=node&node=5716488&i=2> >> >> > > ________________________________ > If you reply to this email, your message will be added to the discussion > below: > http://apache-poi.1045710.n5.nabble.com/POI-3-11-NullPointerException-when-doing-removeSheetAT-for-xls-file-tp5716487p5716488.html > To unsubscribe from POI 3.11 NullPointerException when doing removeSheetAT() > for .xls file, click > here<http://apache-poi.1045710.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5716487&code=a2dhcm5lbmlAYWNtb29yZS5jb218NTcxNjQ4N3wtMjA5NjY0Mzcy>. > NAML<http://apache-poi.1045710.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> > > ________________________________ > Notice: This message and any attachments may contain confidential or > proprietary information and are only for the use of the intended recipient of > this message. If you are not the intended recipient, please notify the sender > by return email, and delete or destroy this and all copies of this message > and all attachments. Any unauthorized disclosure, use, distribution or > reproduction of this message or any attachments is prohibited and may be > unlawful. > > > > > -- > View this message in context: > http://apache-poi.1045710.n5.nabble.com/POI-3-11-NullPointerException-when-doing-removeSheetAT-for-xls-file-tp5716487p5716526.html > Sent from the POI - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
