Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Storing radiobutton into file

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Storing radiobutton 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.

    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');
    	[B][U]writer.write(lbl3 + gender);[/U][/B]
    	    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');
     
        [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());
     
    }

    ignore all the other rubbish around it


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Storing radiobutton into file

    I presume you mean JRadioButton? How do you wish to 'save' this? By the string that defines the Label? Passing the object will cause it to use the Object's toString method...if the results you see are null it means the Object you passed is null. If this makes no sense, I recommend posting something more complete and compilable (eg an SSCCE) to demonstrate the problem that will provide more context to the problem.

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Storing radiobutton into file

    Duplicate thread at java-forums.org

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Storing radiobutton into file


  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Storing radiobutton into file

    Quote Originally Posted by Junky View Post
    Duplicate thread at java-forums.org
    If you post the link to the thread between the CP (cross post) tags, eg: [cp]url here[/cp]
    It will print out the official Cross Posting blurb like in copegs post.

    The X button in the quick reply box will print the CP tags automatically. Thanks.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. [SOLVED] Storing info into a text file & adding to it
    By BlackFlame in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 12th, 2011, 09:06 PM
  2. Storing data
    By Joyce in forum Collections and Generics
    Replies: 1
    Last Post: September 20th, 2010, 09:16 AM
  3. [SOLVED] Reading from a text file and storing in arrayList
    By nynamyna in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 26th, 2010, 09:55 PM
  4. Storing data from a socket to a file in real time
    By colossusdub in forum Java Networking
    Replies: 0
    Last Post: March 2nd, 2010, 09:10 AM
  5. Object creation from a input file and storing in an Array list
    By LabX in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: May 14th, 2009, 03:52 AM