5 Replies Latest reply: Mar 31, 2011 12:51 AM by Darryl Burke RSS

    RadioButton and storing into file

    756024
      ive been working on this for a while and have tried several alternatives and its getting late heh. I am having problems taking a radiobutton, and storing it as a string in a .csv file.
      try{
                if(btn1.isSelected())
                {
                     gender = "Male";
                }
                if(btn2.isSelected())
                {
                     gender = "Female";
                }
           FileWriter writer = new FileWriter("Student.csv");
      
           writer.write(lbl1 + ", " + txt1.getText());         
           writer.write('\n');
           writer.write(lbl1 + ", ");
           
           writer.write('\n');
           [U]writer.write(lbl3 + gender);[/U]
               writer.write('\n');
      
               writer.write(lbl2 + ", " + txt2.getText());
      
           writer.close();
      
           } catch (Exception e){
      
           System.err.println("Error: " + e.getMessage());
      
           }
      The main line i am interested in is the one underlined, every time i try to save it into a .csv file i get an error "null"

      this is the other way i tried.
      String choice = group.getSelection().getActionCommand();
      try{
      
          FileWriter writer = new FileWriter("Student.csv");
      
          writer.write(lbl1 + ", " + txt1.getText());         
      
          writer.write('\n');
      
          writer.write(lbl7 + ", " + choice);
      
          writer.write('\n');
      
          writer.write(lbl2 + ", " + txt2.getText());
      
          writer.close();
      
      } catch (Exception e){
      
          System.err.println("Error: " + e.getMessage());
      
      }
      Edited by: user9196779 on 30-Mar-2011 17:05

      Edited by: EJP on 31/03/2011 11:37: fixed your code tags