![]() |
Quick question.. really Quick
I'm using the following code:
:
System.out.println ("position: " + fileData [i].indexOf ("<GPieceSize>"));I'm getting an error saying that there's a null pointerException. How is this possible? if the value isn't found within the string then a (-1) should be printed. Does anyone understand why there's a null pointer exception? |
fileData[i] is null.
|
Quote:
Would you know what would cause it to be null? |
Here's the code to read in the .txt file and store it in the string array from the above example
:
String temp = ""; |
This code is very inefficient as you read the entire file twice. You should instead use an ArrayList to store each line.
|
So i've given you the part where it reads from the file/ stores it into the array. That part doesn't give me any errors. Now, here's the code where the error comes into play. I've placed it in blue font.
:
int tempLength; |
I believe the problem is occuring as a result of code you have not posted. My guess is that the fileData array has been initialized (eg, String[] fileData = new String[fileCount];) but has not yet been filled with data from the first fragment of code you posted. (As you know, when an object array is first initialized, all of its indices are set to null.) Unless I'm missing something, you'll have to post more code.
|
Quote:
|
It is not being initialized right here?
:
|
Yes. The fileData array is correctly initialized in that code, however that is not the case in the second code fragment you posted. You will have to post the rest of the code.
|
| All times are GMT -5. The time now is 1:41 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC