I have a String[] LinesFromFile which contains about 100 lines loaded from a file e.g.
LinesFromFile[0] is "Line1"
LinesFromFile[1] is "Line2"
LinesFromFile[2] is "Line3"
…
LinesFromFile[99] is "Line100"
I want to now create a new String[] SomeLinesFromFile and assign this variable some of the lines from LinesFromFile.
I would have thought it would have been as simple as:
String[] SomeLinesFromFile = null;
int offset = 45;
for (i = 0; i < 10, i++)
{
SomeLinesFromFile[i] = LinesFromFile[offset + i];
}
I would have assumed this code would set SomeLinesFromFile[0] to SomeLinesFromFile[9] with the values of LinesFromFile[46] through to LinesFromFile[56].
When I try running this on my android device it crashes. What am I missing here?
SomeLinesFromFileisnull, so you cannot then do:You need to create an array first, e.g.:
Incidentally, it is considered bad practice to name your variables starting with capital letters. So you should always use
someLinesFromFileinstead ofSomeLinesForFile.