Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4362: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4364: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4365: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4366: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
anddev.org • View topic - Problem with writing and reading files?

Problem with writing and reading files?

Put your problem here if it does not fit any of the other categories.

Problem with writing and reading files?

Postby ortson » Sat Mar 31, 2012 5:44 pm

Hello everybody!

This is my first post on this forum and i would like some help. I have been developing my first big android application for about a week and a half now and i have a problem which i think depends on the writing and reading of files. So hers some of the code that i've done so far:
This is the class where the data is saved
Code: Select all
public class Aktivitet extends Activity{
   
Button skapa;
EditText etNamn;
String sNamn;

RadioGroup rgKategorier;
RadioButton rbGolf;
RadioButton rbFys;
RadioButton rbMentalt;
RadioButton rbOvrigt;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aktivitet);

        etNamn = (EditText) findViewById(R.id.etNamn);
        skapa = (Button) findViewById(R.id.bSkapa);
        rgKategorier = (RadioGroup) findViewById(R.id.rgKategorier);   
        rbGolf = (RadioButton) findViewById(R.id.rbGolf);
        rbFys = (RadioButton) findViewById(R.id.rbFys);
        rbMentalt = (RadioButton) findViewById(R.id.rbMentalt);
        rbOvrigt = (RadioButton) findViewById(R.id.rbOvrigt);
               
        skapa.setOnClickListener(new View.OnClickListener() {
         
         public void onClick(View v) {
            
            int selectedId = rgKategorier.getCheckedRadioButtonId();
            
            String output = " ";
            String output2 = " ";
            
            sNamn = etNamn.getText().toString();
            
            String FILENAME = "aktivitetInfo.txt";
            String FILENAME2 = "kategoriInfo.txt";

            
            try {
               OutputStreamWriter osw = new OutputStreamWriter(openFileOutput("FILENAME", 0));
               OutputStreamWriter osw2 = new OutputStreamWriter(openFileOutput("FILENAME2", 0));
               if(selectedId == rbGolf.getId()){
                  output = "Golf\n";
                  osw2.write(output);}
               else if(selectedId == rbFys.getId()){
                  output = "Fys\n";
                  osw2.write(output);}
               else if(selectedId == rbMentalt.getId()){
                  output = "Mentalt\n";
                  osw2.write(output);}
               else if(selectedId == rbOvrigt.getId()){
                  output = "Ovrigt\n";
                  osw2.write(output);}
               output2 = sNamn + "\n";
               osw.write(output2);
               osw.close();
               osw2.close();
            } catch (FileNotFoundException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
            }catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
            }
            
            Intent openMainProgram = new Intent("martin.app.development.DSFACTIVITY");
             startActivity(openMainProgram);
         }
      });
       
       
    }
}


And here is the code where i read it in and try to create spinner from it.
Code: Select all
public class Post extends Activity{
      
   Spinner spGolf, spFys, spMentalt, spOvrigt;//Spinners for categories
      
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.post);//SEt post to xml layout

      String inputFile = "aktivitetInfo.txt";//Set upp the input files
      String inputFile2 = "kategoriInfo.txt";
      
      String input = "";//The input taken from files
      String input2 = "";
      
      //Setup spinners
      spGolf = (Spinner) findViewById(R.id.spGolf);
      spFys = (Spinner) findViewById(R.id.spFys);
      spMentalt = (Spinner) findViewById(R.id.spMentalt);
      spOvrigt= (Spinner) findViewById(R.id.spOvrigt);
      
      
      
      String[] kategori = {};
      String[] aktivitet = {};
      
      try {
         InputStream is = openFileInput(inputFile);
         InputStream is2 = openFileInput(inputFile2);
         
         InputStreamReader inputreader = new InputStreamReader(is);
         InputStreamReader inputreader2 = new InputStreamReader(is2);
          BufferedReader buffreader = new BufferedReader(inputreader);
          BufferedReader buffreader2 = new BufferedReader(inputreader2);
         
         input = buffreader.toString();
         input2 = buffreader2.toString();
         
         int length = input.length();
         int length2 = input2.length();
         
         for(int i = 0; i < length; i++){
            String word = "";
            int j = 0;
            if(input.substring(i, i+2) == "\n"){
               aktivitet[j] = word;
               j++;
            }
            else
               word += input.substring(i, i+1);
         }
         for(int i = 0; i < length2; i++){
            String word = "";
            int j = 0;
            if(input2.substring(i, i+2) == "\n"){
               kategori[j] = word;
               j++;
            }
            else
               word += input.substring(i, i+1);
         }
         
         is.close();
         is2.close();
      } catch (FileNotFoundException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
      
      List<String> golfList = new ArrayList<String>();
      List<String> fysList = new ArrayList<String>();
      List<String> mentaltList = new ArrayList<String>();
      List<String> ovrigtList = new ArrayList<String>();
      for(int i = 0; i < kategori.length; i++){
         if(kategori[i] == "Golf"){
            golfList.add(aktivitet[i]);
         }
         else if(kategori[i] == "Fys"){
            fysList.add(aktivitet[i]);
         }
         else if(kategori[i] == "Mentalt"){
            mentaltList.add(aktivitet[i]);
         }
         else{
            ovrigtList.add(aktivitet[i]);
         }
      }
      ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
         android.R.layout.simple_spinner_item, golfList);
      dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spGolf.setAdapter(dataAdapter);
      
      ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, fysList);
      dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spFys.setAdapter(dataAdapter);
      
      ArrayAdapter<String> dataAdapter3 = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, mentaltList);
      dataAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spMentalt.setAdapter(dataAdapter);
   
      ArrayAdapter<String> dataAdapter4 = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, ovrigtList);
      dataAdapter4.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spOvrigt.setAdapter(dataAdapter);
   }
}

I would realy like some help i'm stuck and don't now what to do...

ps. Sorry for bad english im from sweden!
ortson
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Mar 31, 2012 5:29 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 9 guests