processing-website icon indicating copy to clipboard operation
processing-website copied to clipboard

createReader() example has an error

Open thisischrisswift opened this issue 4 years ago • 8 comments

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.

thisischrisswift avatar Sep 05 '20 18:09 thisischrisswift

That could should be correct. Are you getting an error?

benfry avatar Sep 15 '20 01:09 benfry

When I tested it, the example sketch worked fine.

The TAB constant is also evaluating correctly.

print(TAB == '\t');

true

jeremydouglass avatar Sep 15 '20 20:09 jeremydouglass

I get an error ArrayIndexOutOfBoundsException: 1 on line 15. Screen Shot 2020-09-15 at 4 33 20 PM

thisischrisswift avatar Sep 15 '20 20:09 thisischrisswift

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.

jeremydouglass avatar Sep 15 '20 20:09 jeremydouglass

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 avatar Sep 15 '20 20:09 thisischrisswift

@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?

jeremydouglass avatar Sep 17 '20 04:09 jeremydouglass

...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)

jeremydouglass avatar Sep 17 '20 04:09 jeremydouglass

...that's odd: the tab escape looks fine here:

https://github.com/processing/processing-docs/blob/3a62e8484c813c209eb28c5782fa3d1398b0d24f/content/api_en/createWriter.xml#L23

jeremydouglass avatar Sep 17 '20 04:09 jeremydouglass