So I am having this code that should read from every line from every text document in an ftp directoy, the thing is that is only works for det first file because when it comes to the second I can see in the log that the second also gets listed but when it wants to read it just chrash, this is the code
public void getComments(){
final FTPClient ftpClient = new FTPClient();
BufferedReader reader = null;
new Thread(new Runnable() {
public void run() {
try {
ftpClient.connect(InetAddress.getByName("31.220.17.2"));
ftpClient.login("mopedsho", "neppi1");
int imageNr = sharedPreferences.getInt("ImageNrCross", 1);
ftpClient.makeDirectory("/public_ftp/Comments/Cross/" + imageNr);
ftpClient.changeWorkingDirectory("/public_ftp/Comments/Cross/" + imageNr);
String[] names = ftpClient.listNames();
if (names == null) {
} else {
BufferedReader reader = null;
for (String name : names) {
if (!name.equals(".") && !name.equals("..")) {
InputStream in = null;
try {
Log.e("File namer", name + "");
in = ftpClient.retrieveFileStream(name);
if (in != null) {
reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
String firstLine;
while ((firstLine = reader.readLine()) != null) {
final String line = firstLine;
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
adapter.add("" + line);
}
});
}
}
in.close();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
ftpClient.logout();
ftpClient.disconnect();
}
}} catch (UnknownHostException e) {
e.printStackTrace();
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}}
}).start();}
error code:
07-14 13:50:27.739 20152-20298/com.emiliogaines.mopedshowcase E/File namer﹕ EmilioGaines4663767201961631433982.txt
07-14 13:50:28.166 20152-20298/com.emiliogaines.mopedshowcase E/File namer﹕ EmilioGaines4663767201961631535180.txt
07-14 13:50:28.306 20152-20298/com.emiliogaines.mopedshowcase E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-6657
Process: com.emiliogaines.mopedshowcase, PID: 20152
java.lang.NullPointerException: lock == null
at java.io.Reader.<init>(Reader.java:64)
at java.io.InputStreamReader.<init>(InputStreamReader.java:77)
at com.emiliogaiines.mopedshowcase.commentLayout$2.run(commentLayout.java:140)
at java.lang.Thread.run(Thread.java:818)
07-14 13:50:28.431 20152-20152/com.emiliogaines.mopedshowcase I/Ti
the error is pointing to this line
reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));