What is wrong with my code? I get this error every time I run my code. Trying to download a .txt file, and then display the text in the toast. That is all I want!
: FATAL EXCEPTION: main Process: nnsoft.nsomuhtest, PID: 18706
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
at android.widget.Toast.<init>(Toast.java:138)
at android.widget.Toast.makeText(Toast.java:385)
code:
@Override
protected void onPostExecute(String unused) {
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(AnnouncementsDirectory));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
br.close();
Toast.makeText(context, text, Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(context, "error reading ver file", Toast.LENGTH_LONG).show();
}
}