android program bug
<p>I have the following function in android program:</p>

<pre><code>public ArrayList&lt;ArrayList&lt;Sentence&gt;&gt; search(ArrayList&lt;Integer&gt; gestureNumbers, InputStream instream) throws FileNotFoundException, IOException {
        String line="";
        int index;
        String[] splitedLine;
        String[] components = null;
        String[] words = null;
        String word = null;
        String pos = null;
        ArrayList&lt;ArrayList&lt;Sentence&gt;&gt; gestures = new ArrayList&lt;ArrayList&lt;Sentence&gt;&gt;();
        ArrayList&lt;Sentence&gt; gesture;
        ArrayList&lt;String&gt; wordsList = new ArrayList&lt;String&gt;();
        ArrayList&lt;String&gt; partsList = new ArrayList&lt;String&gt;();


       for (int i = 0; i &lt; gestureNumbers.size(); i++) {

        BufferedReader bf = new BufferedReader(new InputStreamReader(instream));
        //possible error here

            while ((line = bf.readLine()) != null) {

                //split line to get gesture number
                splitedLine = line.split("\\#");
                index = Integer.parseInt(splitedLine[0].trim());

                //if the typed gesture number equals to the one in the file
                if (index == gestureNumbers.get(i)) {


                    gesture = new ArrayList&lt;Sentence&gt;();
                    components = splitedLine[1].split("\\]\\[");

                    //get its meanings and add to the array list of gestures
                    //containing word and its part of speech
                    for (int j = 0; j &lt; components.length; j++) {
                        words = components[j].split("\\:");
                        word = words[0].trim();
                        pos = words[1].trim();
//
//                       //if the word is a noun then add "the"

                         if(pos.equalsIgnoreCase("N")){
                             word = "the "+word;
                         }

                        wordsList.add(word);
                        partsList.add(pos);

                        gesture.add(new Sentence(wordsList, partsList));




                        wordsList = new ArrayList&lt;String&gt;();
                        partsList = new ArrayList&lt;String&gt;();
                    }




                    gestures.add(gesture);


                }
            }
        }



        return gestures;
    }
</code></pre>

<p>This function is invoked in an Activity class which passes the gestureNumbers and the input stream using the following code:</p>

<pre><code>public ArrayList&lt;ArrayList&lt;Sentence&gt;&gt; searchGestures(
            ArrayList&lt;Integer&gt; gestureNumbers) throws FileNotFoundException,
            IOException {
        GestureSearcher searcher = new GestureSearcher();
        ArrayList&lt;ArrayList&lt;Sentence&gt;&gt; gestures;
        AssetManager assetManager = getAssets();
        InputStream instream = assetManager.open("BSL_Word_POS.txt");

        gestures = searcher.search(gestureNumbers, instream);

        return gestures;
    }
</code></pre>

<p>The problem I am having is that even if the gestureNumbers.size() > 1 it goes into the while loop only once and finds only the 1st gesture and doesn't look for the next gesture. Once the line = null it stops executing but then I am creating a new BufferedReader so I am not sure why it is still null. This code comes from an original java code which worked fine:</p>

<pre><code>public ArrayList&lt;ArrayList&lt;Sentence&gt;&gt; search(ArrayList&lt;Integer&gt; gestureNumbers) throws FileNotFoundException, IOException {
        String line;
        int index;
        String[] splitedLine;
        String[] components = null;
        String[] words = null;
        String word = null;
        String pos = null;
        ArrayList&lt;ArrayList&lt;Sentence&gt;&gt; gestures = new ArrayList&lt;ArrayList&lt;Sentence&gt;&gt;();
        ArrayList&lt;Sentence&gt; gesture;
        ArrayList&lt;String&gt; wordsList = new ArrayList&lt;String&gt;();
        ArrayList&lt;String&gt; partsList = new ArrayList&lt;String&gt;();

        BufferedReader bf;

        for (int i = 0; i &lt; gestureNumbers.size(); i++) {
            bf = new BufferedReader(new FileReader("path\\BSL_Word_POS.txt"));
            while ((line = bf.readLine()) != null) {

                //split line to get gesture number
                splitedLine = line.split("\\#");
                index = Integer.parseInt(splitedLine[0].trim());

                //if the typed gesture number equals to the one in the file
                if (index == gestureNumbers.get(i)) {


                    gesture = new ArrayList&lt;Sentence&gt;();
                    components = splitedLine[1].split("\\]\\[");

                    //get its meanings and add to the array list of gestures
                    //containing word and its part of speech
                    for (int j = 0; j &lt; components.length; j++) {
                        words = components[j].split("\\:");
                        word = words[0].trim();
                        pos = words[1].trim();
//


                        //if the word is a noun then add "the"

                         if(pos.equalsIgnoreCase("N")){
                             word = "the "+word;
                         }





                        wordsList.add(word);
                        partsList.add(pos);

                        gesture.add(new Sentence(wordsList, partsList));




                        wordsList = new ArrayList&lt;String&gt;();
                        partsList = new ArrayList&lt;String&gt;();
                    }




                    gestures.add(gesture);


                }
            }
        }
</code></pre>
