# My program keeps crashing; STRING (file) to INT

**URL:** <https://discourse.processing.org/t/my-program-keeps-crashing-string-file-to-int/16872>\
**Category:** Coding Questions\
**Created:** [January 4, 2020, 10:52pm UTC](https://discourse.processing.org/t/my-program-keeps-crashing-string-file-to-int/16872 "2020-01-04T22:52:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 4, 2020, 10:52pm UTC](https://discourse.processing.org/t/my-program-keeps-crashing-string-file-to-int/16872/1 "2020-01-04T22:52:15Z")

</div>

the first segment of code is the issue, without it, it works fine. I have tried int(string), Intiger.valueOf and Intiger.ParseInt. If you have any ideas pls tell me. (btw i saw no issue with the file, if you want i can link it, but its just random Slovenian words)

```auto
//Trying to find a word with different search methods, from a .txt document called "besede.txt"

//loading the number of word in the .txt from the first line of it.
String wLen = loadStrings("besede.txt")[0];
int intA = int(wLen); //trying to change String to Int, i'vs seen it work
  

int wnum = intA; //int(loadStrings("besede.txt")[0]); //number of words
String words[] = new String[intA];

int wl = 7; //word length //one of the search parimiters; length of the word

boolean searchBy[] = {true,false,false}; //1st - length, 2nd- letters, 3rd- letters known

String output[] = new String[wnum]; //output of all of the words, matching the criteria

int ol = 0; //output length

void setup() {
  
  size(100,100);  
  for(int i = 0; i < wnum; i++) { //loading all the words from .txt
    words[i] = loadStrings("besede.txt")[i+1];
  }
  //for(int i = 0; i < wnum; i++) {
  // println(words[i]);
  //}
}
void draw() {
  //first criteria; length test
  for(int i = 0; i < wnum; i++) {
    if(words[i].length() == wl) {
      output[ol] = words[i];
      ol++;
    }
  }
  finish();
}

void finish() {
  for(int i = 0; i < ol; i++) {
    println(output[i]);
  }
  exit();
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 4, 2020, 11:20pm UTC](https://discourse.processing.org/t/my-program-keeps-crashing-string-file-to-int/16872/2 "2020-01-04T23:20:01Z")

</div>

Please study reference for [loadStrings](https://processing.org/reference/loadStrings_.html)

Also study tutorial for array

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [January 5, 2020, 3:53am UTC](https://discourse.processing.org/t/my-program-keeps-crashing-string-file-to-int/16872/3 "2020-01-05T03:53:10Z")

</div>

There a re few things you can do yourself before asking for help.

First, you can isolate the problem: Trying running the culprit lines in a sketch by themselves.

Second: Use `print()` to see what the values you are converting

Third: Always check you dont have a null case

Fourth: Base on the error, do a search online and in the forum

If the issue persist, share your code and tell us what you tried.

Now, I have to add that you are doing something you suppose not to do. In the code you provided above, you are adding code outside setup and draw functions. For instance, the proper way to do it:

```auto

String wLen ;
int intA ;

void setup(){
  size(100,100);  
  String wLen = loadStrings("besede.txt")[0];
  int intA = int(wLen); //trying to change String to Int, i'vs seen it work

  ... //Rest of the code

```

Please check the second bullet in the [Troubleshooting guide](https://github.com/processing/processing/wiki/troubleshooting#common-issues-that-are-not-bugs) under the section: _Common Issues (That Are Not Bugs)_.

Kf
