I'm very new to android programming, but I have some experience in Java and C++. While I have been able to do much of the program, I'm stuck with a NPE in FileInputStream. I'm trying to create an Attendance program, which tracks the attendance of a student in lectures. Here's the code which throws the NPE:
public class Attendance extends Activity {
Subject s[] = new Subject[13];
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
for(int i=0;i<13;i++) {
s[i] = new Subject();
}
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void loadData(Subject s[]) throws IOException{
for(int i=0;i<13;i++) {
int a[] = new int [2];
int x=0;
try {
FileInputStream fIn = openFileInput("s["+i+"].txt");
InputStreamReader isr = new InputStreamReader(fIn); //NPE occurs here
//char buff[] = new char[100];
//isr.read(buff);
BufferedReader br = new BufferedReader(isr);
String str = new String();
while ((str=br.readLine())!=null) {
a[x]=Integer.parseInt(str);
x++;
}
s[i].acceptAttd(a[0]);
s[i].acceptLecs(a[1]);
}
catch(IOException e) {
//do nothing.
}
}
}
public void addAttnd(View v) throws IOException{
setContentView(R.layout.addattnd2);
Attendance a = new Attendance();
a.loadData(s); //this line calls the method containing FileInputStream
}