Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving files doesn't work always android
    text
    copied!<p>So what started as A problem with buttons, just means there is A problem with my files. I want to save numbers to my files, and also wich languege I selected. The languege works perfect but when I try to do the same with my numbers it just go wrong</p> <p>So this is the code of my languege file</p> <pre><code>french.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try{ buttonSound.start(); String FILENAME = "LangFile"; String data ="FR"; FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE); fos.write(data.getBytes()); fos.close(); FILENAME="TempFile"; data="0"; FileOutputStream fostemp = openFileOutput(FILENAME, Context.MODE_PRIVATE); fostemp.write(data.getBytes()); fostemp.close(); startActivity(new Intent("com.technopolisapp.LOGOTECHNOPOLIS")); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally{ finish(); } } }); </code></pre> <p>Here I save 2 letters for the button pressed And this is the code that reads it again and make A the buttons with the languege chosen</p> <pre><code>try{ String FILENAME = "LangFile"; FileInputStream fos = openFileInput(FILENAME); byte[] b = new byte[2]; fos.read(b); fos.close(); if(new String(b).equalsIgnoreCase("NL")){ Tower.setText(classNamesDutch[0]); Puzzle.setText(classNamesDutch[1]); Mirror.setText(classNamesDutch[2]); Tangram.setText(classNamesDutch[3]); Frog.setText(classNamesDutch[4]); } if(new String(b).equalsIgnoreCase("GB")){ Tower.setText(classNamesEnglish[0]); Puzzle.setText(classNamesEnglish[1]); Mirror.setText(classNamesEnglish[2]); Tangram.setText(classNamesEnglish[3]); Frog.setText(classNamesEnglish[4]); } if(new String(b).equalsIgnoreCase("FR")){ Tower.setText(classNamesFrench[0]); Puzzle.setText(classNamesFrench[1]); Mirror.setText(classNamesFrench[2]); Tangram.setText(classNamesFrench[3]); Frog.setText(classNamesFrench[4]); } }catch (java.io.FileNotFoundException e) { } catch (IOException e) { e.printStackTrace(); } </code></pre> <p>Now this is my code for saving and reading for my numbers</p> <pre><code>public void Savefile(){ int level=0; String data; try{ String FILENAME = "TowerFile"; FileInputStream fos = openFileInput(FILENAME); byte[] b = new byte[1]; fos.read(b); fos.close(); if(new String(b).equalsIgnoreCase("1")){ level=1; } if(new String(b).equalsIgnoreCase("2")){ level=2; } if(new String(b).equalsIgnoreCase("3")){ level=3; } if(new String(b).equalsIgnoreCase("4")){ level=4; } if(new String(b).equalsIgnoreCase("5")){ level=5; } if(level!=1 || level!=2 || level!=3 || level!=4 || level!=5){ FILENAME="TowerFile"; data="een"; FileOutputStream fostemp = openFileOutput(FILENAME, Context.MODE_PRIVATE); fostemp.write(data.getBytes()); fostemp.close(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } </code></pre> <p>And this is the way I want to read it</p> <pre><code>try{ String FILENAME = "TowerFile"; FileInputStream fos = openFileInput(FILENAME); byte[] b = new byte[1]; fos.read(b); fos.close(); if(new String(b).equalsIgnoreCase("1")){ button1.setVisibility(Button.GONE); } if(new String(b).equalsIgnoreCase("2")){ level=2; } if(new String(b).equalsIgnoreCase("3")){ level=3; } if(new String(b).equalsIgnoreCase("4")){ level=4; } if(new String(b).equalsIgnoreCase("5")){ level=5; } }catch (java.io.FileNotFoundException e) { } catch (IOException e) { e.printStackTrace(); } </code></pre> <p>So I don't really get it where it goes wrong at the moment</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload