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

**URL:** <https://discourse.processing.org/t/error-on-saving-file-if-the-string-has-chars-sourced-from-the-key-variable/13731>\
**Category:** Processing for Android\
**Created:** [August 31, 2019, 9:20pm UTC](https://discourse.processing.org/t/error-on-saving-file-if-the-string-has-chars-sourced-from-the-key-variable/13731 "2019-08-31T21:20:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hutty](https://avatars.discourse-cdn.com/v4/letter/h/7c8e57/32.png) [@hutty](https://discourse.processing.org/u/hutty)\
**Post date:** [August 31, 2019, 9:20pm UTC](https://discourse.processing.org/t/error-on-saving-file-if-the-string-has-chars-sourced-from-the-key-variable/13731/1 "2019-08-31T21:20:30Z")

</div>

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

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

```

works

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

```

crashes

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

[![](https://img.youtube.com/vi/OyhbU37Z21U/maxresdefault.jpg "Programming issue.") ](https://www.youtube.com/watch?v=OyhbU37Z21U)

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.

---

<div class="post-metadata">

**Author:** ![hutty](https://avatars.discourse-cdn.com/v4/letter/h/7c8e57/32.png) [@hutty](https://discourse.processing.org/u/hutty)\
**Post date:** [September 1, 2019, 8:49am UTC](https://discourse.processing.org/t/error-on-saving-file-if-the-string-has-chars-sourced-from-the-key-variable/13731/2 "2019-09-01T08:49:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [September 1, 2019, 4:07pm UTC](https://discourse.processing.org/t/error-on-saving-file-if-the-string-has-chars-sourced-from-the-key-variable/13731/3 "2019-09-01T16:07:10Z")

</div>

Hi. I think This is related to [this](https://discourse.processing.org/t/special-characters-problems-in-apde/13433) , 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.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 9, 2019, 12:40am UTC](https://discourse.processing.org/t/error-on-saving-file-if-the-string-has-chars-sourced-from-the-key-variable/13731/4 "2019-09-09T00:40:24Z")

</div>

> [@hutty](#):
>
> Removing the first character of a string created from the key variable with substring seems to do the trick to making it work.

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

> **[Issues · processing/processing-android](https://github.com/processing/processing-android/issues)**
>
> Processing mode and core library to create Android apps with Processing - Issues · processing/processing-android
