I need to create a String ArrayList from another String ArrayList by splitting the strings from the first one into the second one. The data comes from a .txt file being read in by a BufferedReader. This app is supposed to display a spinner from which the user can choose a student's name then calculate their grade and display that as well. The biggest hurdle right now is that I get a null pointer exception when I try to use .split. As you can probably tell, I'm fairly new to this and could use some help. Thanks!
grades.txt
Name Test1 Test2 Test3 Final
Adam Anderson 81 90 85 87
Ben Brown 77 80 68 94
Chris Cross 74 80 56 62
Don Dare 86 94 90 89
Eric Earl 96 93 90 98
Fred Foley 79 92 59 86
Gina Gray 80 83 95 87
Holly Hank 74 77 75 78
Ian Ingram 66 64 56 60
Jill Johnson 90 98 78 89
java code
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String strName, strLastName, strFirstName, strFinalGrade;
int intTest1, intTest2, intTest3, intFinal, intFinalGrade;
int intPointsPossible = 400;
int finalGrades[] = new int[0];
AssetManager am = getAssets();
ArrayList<String> list = new ArrayList<String>();
ArrayList<String> finalList = finalList = new ArrayList<String>();
BufferedReader reader;
String line = " ";
String item = " ";
try {
InputStream input = am.open("grades.txt");
reader = new BufferedReader(new InputStreamReader(input));
while (line != null){
line = reader.readLine();
list.add(line);
}
while (item != null){
for (int i = 0; i < list.size(); i++){
line.split("\\s+");
finalList.add(item);
}
}
input.close();
} catch (IOException e) {
e.printStackTrace();
}
Spinner spinner = new Spinner(this);
ArrayAdapter<String> dataAdapter =
new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
spinner.setAdapter(dataAdapter);
dataAdapter.notifyDataSetChanged();
}}
line.split("\\s+");returns aString[], should you be doing something with that?while (item != null)... this is an infinite loop