Results 1 to 4 of 4
  1. #1
    Aretium is offline Member
    Join Date
    Mar 2011
    Posts
    1
    Rep Power
    0

    Default Storing radio button into file

    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.

    Java Code:
    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][B]writer.write(lbl3 + gender);[/B][/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.


    Java Code:
    String choice = group.getSelection().getActionCommand();
    try{
    
    FileWriter writer = new FileWriter("Student.csv");
    
    
    
    writer.write(lbl1 + ", " + txt1.getText());	    
    
        writer.write('\n');
    
        [B][U]writer.write(lbl7 + ", " + choice);[/U][/B]
    
        writer.write('\n');
    
        writer.write(lbl2 + ", " + txt2.getText());
    
    writer.close();
    
    } catch (Exception e){
    
    System.err.println("Error: " + e.getMessage());
    
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Quote Originally Posted by Aretium View Post
    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 leads me to believe that neither btn1 or btn2 is selected. Thus gender is never assigned a value and retains its default value of null. time for you to do some debugging.

  3. #3
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

Similar Threads

  1. Radio Button
    By S-NESH in forum New To Java
    Replies: 6
    Last Post: 02-04-2011, 05:03 PM
  2. Clear Radio Button
    By Reborn in forum New To Java
    Replies: 6
    Last Post: 07-25-2010, 05:21 PM
  3. Radio Button help!
    By javanator in forum New To Java
    Replies: 3
    Last Post: 04-25-2010, 08:01 PM
  4. Radio button dot color
    By Psyclone in forum AWT / Swing
    Replies: 3
    Last Post: 02-21-2010, 04:29 AM
  5. How to use SWT Radio Button
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 02:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •