所以我试图从android中的文件中读取。我初始化了所有东西,但我仍然得到一个NullPointerException。我错过了什么吗?
在第 25 行收到错误。
public class Read {
private ArrayList<String> contents;
private final String filename = "saves/user.txt";
public Read(Context context) {
try {
contents = new ArrayList<String>();
InputStream in = context.getAssets().open(filename);
if (in != null) {
// prepare the file for reading
InputStreamReader input = new InputStreamReader(in);
BufferedReader br = new BufferedReader(input);
String line = br.readLine();
while (line != null) {
contents.add(line);
}
in.close();
}else{
System.out.println("It's the assests");
}
} catch (IOException e) {
System.out.println("Couldn't Read File Correctly");
}
}
public ArrayList<String> loadFile() {
return this.contents;
}
}