TRAIN_NUM.add(cell.toString());
James Boswell wrote:It would be more useful if you posted a snippet of your code where the problem is occurring rather than simply one line. That way, you are more likely to get help faster.
Ulf Dittmer wrote:So either TRAIN_NUM or cell could be null - which one is it?
The ArrayList TRAIN_NUM is empty in the beginning, but that shouldn't be a problem.
James Boswell wrote:
The ArrayList TRAIN_NUM is empty in the beginning, but that shouldn't be a problem.
That depends. How have you initialised the list?
ArrayList <String> TRAIN_NUM = new ArrayList <String>();
Ulf Dittmer wrote:Have you ascertained by now whether either TRAIN_NUM or cell is null?
Ulf Dittmer wrote:You're confusing something in the spreadsheet having some value with a Java object being null. There may be a connection, but there needn't be.
But you're getting a NullPointerException, which means that some Java object is definitely null. The stack trace even tells you in which line that causes a problem. Finding out which object that is is the obvious next step in debugging this. That's why I keep asking about it.
int rows = Sname.getLastRowNum();
Ulf Dittmer wrote:I seem to recall that getLastRowNum does not return the last row number that has data, but the overall last row number (or something like that). So you need to check all the data you get from the file whether or not they actually contain valid data (or are null, since you keep getting NPEs).
Jil Van Wetter wrote:There must be a way to fix this (maybe an update button in Excel or something like that), since I have a lot of files to work with and I cannot enter for each file seperately the last row number with data in it.
Steve
Ulf Dittmer wrote:Well, as I have said a number of times by now, you need to find out which Java object is null. Then you can work back from that and try to figure out *why* it is null (and then take further steps based on that). So far it seems -possibly a mistaken impression- that you're trying to guess what might be going wrong, instead of taking concrete steps to find out for sure what is going wrong.
And no, you don't need to determine for each file how big it is, you just need to write code that performs proper checks on the data it reads.
Stuart A. Burkett wrote:
Jil Van Wetter wrote:There must be a way to fix this (maybe an update button in Excel or something like that), since I have a lot of files to work with and I cannot enter for each file seperately the last row number with data in it.
I don't know if there is a way to fix the files in Excel, but you can fix the problem in your code by wrapping lines 14 - 23 in the code you posted above in an if statement that checks if cell is null
Edit: This of course assumes that it is the cell variable that is null. As Ulf said, the first thing you should do is find out which variable is causing the NPE.
Consider Paul's rocket mass heater. |