processing-docs
processing-docs copied to clipboard
createReader() example has an error
Issue description
createReader() example line 12 has an error. String[] pieces = split(line, TAB);
URL(s) of affected page(s)
https://processing.org/reference/createReader_.html
Proposed fix
should read String[] pieces = split(line, "t"); that is the the .txt file in the createWriter example uses.
That could should be correct. Are you getting an error?
When I tested it, the example sketch worked fine.
The TAB constant is also evaluating correctly.
print(TAB == '\t');
true
I get an error ArrayIndexOutOfBoundsException: 1
on line 15.
What does your positions.txt file look like, and where is it located? It needs to be in the sketch path and to contain tab-separated lines, like
10 10
20 20
30 30
50 50
Clearly you aren't getting an error opening the file, but could the file contents have changed? Or you might be opening a file other than the one you think you are. You can also open a thread on the forum to walk through getting the example working.
I am using a position.txt that is generated for the createWriter(); example here https://processing.org/reference/createWriter_.html. It is in the data folder of the sketch. When I open position.txt I see this: 46t41 52t37 53t36 54t35
It does seem like a tutorial issue and not a program issue.
@thisischrisswift sorry to be dense, I must be tired -- where exactly are you getting that positions.txt file with t
chars rather than tabs in it? For example, when I open PDE > File > Sketchbook > Topics > File IO > LoadFile1 / data / positions.txt in PDE 3.5.4, I see a file with valid \t tab characters.
Any possibility you accidentally modified the file you are using?
...aaand I figured it out. You meant the CreateWriter example itself online. Yes, it has an error.
output.println(mouseX + "t" + mouseY)
That should be:
output.println(mouseX + "\t" + mouseY)
...that's odd: the tab escape looks fine here:
https://github.com/processing/processing-docs/blob/3a62e8484c813c209eb28c5782fa3d1398b0d24f/content/api_en/createWriter.xml#L23