Note that there are some explanatory texts on larger screens.

plurals
  1. POInputStreamReader throws NPE on second iteration of for loop
    primarykey
    data
    text
    <p>InputStreamReader throws an NPE as follows when I execute this code on the second iteration of the for loop. The code works perfectly for the first iteration and returns the following NPE on the second iteration. I am using the code snippet to read contents of specific file from an FTP location and display them. Please note all the lines till the new InputStreamReader work perfectly even on second iteration. Any ideas why?</p> <pre><code>Exception in thread "main" java.lang.NullPointerException at java.io.Reader.&lt;init&gt;(Reader.java:61) at java.io.InputStreamReader.&lt;init&gt;(InputStreamReader.java:55) at com.test.txtweb.server.task.CallBackRetryTask.main(CallBackRetryTask.java:229) </code></pre> <p>Here is the source code:</p> <pre><code>public static void main(String[] args){ String strDate = "20130805"; FTPClient ftpClient = new FTPClient(); try { ftpClient.connect(host); String pathToFiles = "/path/to/File"; String ftpFileName = ""; List&lt;String&gt; ftpFileNames = null; InputStream iStream; if(ftpClient.login(username, password)){ ftpClient.enterLocalPassiveMode(); FTPFile[] ftpFiles = ftpClient.listFiles(); ftpFileNames = new ArrayList&lt;String&gt;(); for (FTPFile ftpFile : ftpFiles) { ftpFileName = ftpFile.getName(); if(ftpFileName.contains(strDate)){ iStream = ftpClient.retrieveFileStream(pathToFiles + ftpFileName); System.out.println(ftpClient.getReplyString()); InputStreamReader isr = new InputStreamReader(iStream); //Error on this line on second iteration BufferedReader br = new BufferedReader(isr); String line = ""; while ((line = br.readLine()) != null) { System.out.println(line); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload