Error on Saving File, if the string has chars sourced from the key variable

I’m working on an android processing app with APDE and have an issue.
When I save a PImage, with save(), with a valid file path it works.
However if I make that filepath string from a string of my text entry box, it doesn’t work, even if it is the same string (according to print() ).

I get a java.io.FileNotFoundException: Invalid file path

The will happen whether the file at the listed path exists or not, and with a hard-coded string it will create the file if there is none.

to simplify

String path = "/storage/emulated/0/MyApp/";
pimage.save(path+"imageName"+".png");

works

String path = "/storage/emulated/0/MyApp/";
pimage.save(path+"imageName"+key+".png");

crashes

I’ve created a video showing the issue in depth here.

I’m not sure what could be causing it, maybe an issue of individual chars within the string having different formats? I’m not sure, I ran out of possible leads so I’ve come here for help.

2 Likes

I’ve found the issue.
Strings created with the key variable will have an invisible width-less character at the start that makes the string different than expected.

This can be detected by printing the string length and noticing that it is one character longer than it should be.

Removing the first character of a string created from the key variable with substring seems to do the trick to making it work.

Although stabilizing saving on android as a whole should be improved, almost every aspect of it seems to be filled with curious bugs or other inconsistent behavior.

4 Likes

Hi. I think This is related to this , a topic from @Eeyorelife I tried to answer.
But when I write “println(s.length());” within mousePressed() I just get a string length of 1. I was expecting two characters because when I hit a backspace the letter will appear.

Thanks. Did you submit this bug as an issue – or is there an issue open for this already?