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.
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');
[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.
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());
}
ignore all the other rubbish around it
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.
Re: Storing radiobutton into file
Duplicate thread at java-forums.org
Re: Storing radiobutton into file
Re: Storing radiobutton into file
Quote:
Originally Posted by
Junky
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.