Solutions from all other similar threads crashes my app, that's why I had to create this thread.
The string:
FileInputStream fis = null;
String collected = null;
try {
File file = new File(FILENAME);
if(!file.exists())
createfileinstantly();
fis = openFileInput(FILENAME);
byte[] dataArray = new byte [fis.available()];
while (fis.read(dataArray) != -1)
{
collected = new String(dataArray);
}
....
Here, "collected" is the string that I want to split. The default value of the string is: "0|0|0|0|0|0|0|0|0" So I want to use " | " to separate these values.
When I add the following code after the above mentioned code, I get null 9 times:
String[] separated = collected.split("|");
String splay = separated[0];
String swin = separated[1];
String sall = separated[2];
String sanimal = separated[3];
String scountry = separated[4];
String sfruit = separated[5];
String shuman = separated[6];
String soccupation = separated[7];
String smisc = separated[8];
To test the code I'm using a TextView called dataResults:
dataResults.setText(splay+swin+sall+sanimal+scountry+sfruit+shuman+soccupation+smisc);
I originally wanted to convert these strings to integer (I still want to) so at first I thought there was some problem while converting to integer. But after some testing out it turns that the issue is in splitting the strings. But just to be on the safer side after the main problem could you please add how to convert the split-ed strings to integer.
Thank you very much!
EDIT: Even after changing "|" to "\\|" it is still showing "null" 9 times. Is that different enough?