CSA 6.10 Natural Language Processing Project - FileReader.textToString Error

One of my students is attempting to use FileReader.textToString to import text files into an ArrayList as was done in Lesson 6.7, option a.

In 6.7a the code reads as follows:

import java.util.ArrayList;

public class WebsiteRunner {
public static void main(String args) {

// Creates an ArrayList of articles
ArrayList<String> articles = new ArrayList<String>();

My student’s code reads as follows:

import java.util.ArrayList;
public class NLPRunner {
public static void main(String args) {

ArrayList<String> review= new ArrayList<String>();

The code in 6.7a runs perfectly fine, yet my student is getting a cannot find symbol error with respect to textToString. I have literally spent hours looking at her code trying to figure out what the problem might be to no avail. I have seen on the forums that there are known issues related to a custom version of FileReader that is inconsistently attached to levels in the CSA curriculum. Is this the case for 6.10? I haven’t been able to find anything related to this specific issue on the forums, but I can’t think of anything else that might be causing the issue.

1 Like

Hi Christopher,
I’m sorry you are having a hard time with the FileReader in this lesson! The information about how to use the FileReader class is in the instructions area on this lesson, see the screenshot at the bottom of this post.

From what you have here, you would want to do something that looks more like this:
articles = FileReader.toStringList(“ramen.txt”);

ramen.txt should be a txt file in the project that has Strings in it. Each line in the txt file will be put into a different index in the ArrayList. Using the FileReader in this way means that you will not need to use the add method to create the ArrayLists.

One other detail to note is that students will need to add in the import statement for the ArrayList class, which you have in your student’s code-- I just wanted to highlight this for other teachers.

Here is a link to a short program I created that uses a .txt file and creates an ArrayList from it using FileReader:

1 Like

Thanks for the assistance.

So I am correct that the FileReader in 6.10 is different from the FileReader in 6.7? If so, that is extremely irritating. I really don’t understand why it would make any sense to show students how to import text files one way in 6.7 and then prevent them from doing it that way in the unit project just three lessons later. It would be really helpful if code.org would just provide us with a single FileReader that works the same way across all of the lessons instead of constantly changing it.

In any case, using toStringList seems to be a partial solution, in that it allows for a single text file to be imported as an ArrayList, but the problem remains that my student has three text files that she wants to import into a single ArrayList. Is there a simple way to do this without the ability to use the textToString method the students were shown in 6.7?

Hi @crodgers, I may have a solution to merge the three ArrayLists into one list. Here is what I found:

Using List.addAll()

The addAll() method is the simplest way to append all of the elements from the given list to the end of another list. Using this method, we can combine multiple lists into a single list.

Merge arraylists example

ArrayList<String> listOne = new ArrayList<>(Arrays.asList("a", "b", "c"));
ArrayList<String> listTwo = new ArrayList<>(Arrays.asList("c", "d", "e"));

listOne.addAll(listTwo);  //Merge both lists

Is this what you had in mind?


Yes, I think that would indeed help. We already found an alternate workaround (she just copied the contents of each text file into a single file), but this is good to know for future reference. Is addAll() a method of the ArrayList class? I do not see it in the documentation, but perhaps I am not looking in the right place.

Hey @crodgers, I’m glad y’all found a work around. addAll() is part part of the ArrayList class. If you want to see the Oracle documentation you can find it here.


1 Like