pls help me with my codes, age doesn't appear on the text file and i got end of file error when i click "view" button. can someone kind enough to fix this..god bless and more power =)

           my code >>>>>> http://www.2shared.com/file/8whfrcUJ/Frame1.html

Post the code here - don't expect people to go looking for it somewhere else.

how to post the code i get errors... =)

btw im using old version of JCreator LE 5.0 and my JDK is 1.6_0.41 its what we use in school cause free versions..

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

class Frame1 extends Frame implements ActionListener
{
String msg="";
Button btnNew,btnSubmit,btnView;
Label lblName,lblAge,lblAddr,lblGender,lblcourse;
TextField txtName,txtAge;
TextArea txtAddr,txtAns;
CheckboxGroup ChkGrp;
Checkbox chkMale,chkFemale;
Checkbox chkCOE,chkCS,chkIT,chkBA;


 Frame1(String name)
{
    super(name);
    setLayout(new GridLayout(3,2));

    lblName = new Label("Name: ");

    lblAge = new Label("Age: ");
    lblAddr = new Label("Address: ");
    lblGender = new Label("Gender: ");
    lblcourse = new Label("Course: ");

    txtName = new TextField();
    txtAge = new TextField();
    txtAddr = new TextArea();
    ChkGrp = new CheckboxGroup();
    chkMale = new Checkbox("Male",ChkGrp,false);
    chkFemale = new Checkbox("Female",ChkGrp,false);
    chkCOE = new Checkbox("COE");
    chkCS = new Checkbox("CS");
    chkBA = new Checkbox("BA");
    chkIT = new Checkbox("IT");
    btnNew = new Button("NEW");
    btnSubmit = new Button("SUBMIT");
    btnView = new Button("VIEW");

    btnNew.addActionListener(this);
    btnSubmit.addActionListener(this);
    btnView.addActionListener(this);

    add(lblName);
    add(txtName);
    add(lblAge);
    add(txtAge);
    add(lblAddr);
    add(txtAddr);
    add(lblGender);
    add(chkMale);
    add(chkFemale);
    add(lblcourse);
    add(chkCS);
    add(chkIT);
    add(chkCOE);
    add(chkBA);
    add(btnNew);
    add(btnSubmit);
    add(btnView);
}
public void actionPerformed(ActionEvent ae)
{
    String s="";
    boolean b;
    FileInputStream Fin;
    DataInputStream dis;
    FileOutputStream Fout;
    DataOutputStream dos;

    try
    {
        Fout = new FileOutputStream("D:/Users/seifer/Desktop/Biodata.txt",true);
        dos = new DataOutputStream(Fout);

        String str = ae.getActionCommand();
        if(str.equals("SUBMIT"))
        {
            s=txtName.getText().trim();
            dos.writeUTF(s);
            dos.writeInt(Integer.parseInt(txtAge.getText()));
            s=txtAddr.getText();
            dos.writeUTF(s);
            if(chkMale.getState())
                dos.writeUTF("Male");
            if(chkFemale.getState())
                dos.writeUTF("Female");

            s="";
            if(chkCOE.getState())
                s="COE";

            if(chkCS.getState())
                s+="CS";

            if(chkIT.getState())
                s+="IT";

            if(chkBA.getState())
                s+="BA";

            s+="!";
            dos.writeUTF(s);
            Fout.close();
        }

        if(str.equals("VIEW"))
        {
            String tmp,name,addr,gender,course;
            int age;
            Fin = new FileInputStream("D:/Users/seifer/Desktop/Biodata.txt");
            dis = new DataInputStream(Fin);

            int i=0,j;

            while(Fin.available()>0)
            {
                name = dis.readUTF();
                age  = dis.readInt();
                addr = dis.readUTF();
                gender = dis.readUTF();
                course = dis.readUTF();

                if(name.equals(txtName.getText().trim()))
                  {
                    txtAge.setText(age+"");
                    txtAddr.setText(addr);
                    if(gender.equals("Male"))
                        chkMale.setState(true);
                    else
                        chkFemale.setState(true);
                    while(course.charAt(i)!='!')
                    {
                        j=course.indexOf('!');
                        tmp = course.substring(i,j);

                        if(tmp.equals("COE"))
                            chkCOE.setState(true);

                        if(tmp.equals("CS"))
                            chkCS.setState(true);

                        if(tmp.equals("IT"))
                            chkIT.setState(true);

                        if(tmp.equals("BA"))
                            chkBA.setState(true);
                        i=j;
                    }
                    break;
                }
            }
            Fin.close();
        }
        if(str.equals("NEW"))
        {
            txtName.setText("");
            txtAge.setText("");
            txtAddr.setText("");
            chkMale.setState(false);
            chkFemale.setState(false);
            chkCOE.setState(false);
            chkCS.setState(false);
            chkIT.setState(false);
            chkBA.setState(false);
        }
    }
    catch(Exception e)
    {
        System.out.println("The Exception Is : " +e);
    }
}
}
class Bio2
{
public static void main(String args[])
{
    try{
    Frame1 F = new Frame1("Biodata");
    F.setSize(800,600);
    F.show();
    }catch(Exception e)
    {
        System.out.println(e);
        System.exit(1);
    }
}
}

You create a grid layout 3x2 (6 components) then add 17 components to it.
For your eof error put some print statements into the read loop so you can see how many records it's reading, exactly where it hits eof etc.

thanks im new to this, i made the grid 17x1 its way better now thank you.. but i lost you with the eof T_T

what to do with the age it does not appear on the text file

please help master cherrill

You write age as an int - a 32 bit binary value - it won't appear as text, just as 0-4 characters of garbage. You will need a binary file editor to see it properly.
For the eof, let's start with the info that Java already provides. In your catch block replace
System.out.println("The Exception Is : " +e);
with
e.printStackTrace();
that will give you a lot more info, including the exact line of your code where the error happened.

im done with the age, i made it same with name, no longer int thanks thanks again

nothing happens with the stacktrace and the +e...

The Exception Is : java.io.EOFException
java.io.EOFException
at java.io.DataInputStream.readFully(DataInputStream.java:180)
at java.io.DataInputStream.readUTF(DataInputStream.java:592)
at java.io.DataInputStream.readUTF(DataInputStream.java:547)
at Frame1.actionPerformed(Frame1.java:125)
at java.awt.Button.processActionEvent(Button.java:392)
at java.awt.Button.processEvent(Button.java:360)
at java.awt.Component.dispatchEventImpl(Component.java:4660)
at java.awt.Component.dispatchEvent(Component.java:4488)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:674)
at java.awt.EventQueue.access$400(EventQueue.java:81)
at java.awt.EventQueue$2.run(EventQueue.java:633)
at java.awt.EventQueue$2.run(EventQueue.java:631)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:647)
at java.awt.EventQueue$3.run(EventQueue.java:645)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:644)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

So let's look at the stack trace, starting at the bottom (earliest call)...
lines 28-7 are Java's event handling getting the button press and calling your actionPerformed.
on line 6 your actionPerformed is seen calling readUTF, which leads to an eof exception.
line 6 also tells us that the particular readUTF that caused the problem was on line 125 of your Frame1.java file, so which line is that exactly in your latest version of the code?

   import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
class Frame1 extends Frame implements ActionListener
{
String msg="";
Button btnNew,btnSubmit,btnView;
Label lblName,lblAge,lblAddr,lblGender,lblcourse;
TextField txtName,txtAge;
TextArea txtAddr,txtAns;
CheckboxGroup ChkGrp;
Checkbox chkMale,chkFemale;
Checkbox chkCOE,chkCS,chkIT,chkBA;
 Frame1(String name)
{
super(name);
setLayout(new GridLayout(17,1));
lblName = new Label("Name: ");
lblAge = new Label("Age: ");
lblAddr = new Label("Address: ");
lblGender = new Label("Gender: ");
lblcourse = new Label("Course: ");
txtName = new TextField();
txtAge = new TextField();
txtAddr = new TextArea();
ChkGrp = new CheckboxGroup();
chkMale = new Checkbox("Male",ChkGrp,false);
chkFemale = new Checkbox("Female",ChkGrp,false);
chkCOE = new Checkbox("COE");
chkCS = new Checkbox("CS");
chkBA = new Checkbox("BA");
chkIT = new Checkbox("IT");
btnNew = new Button("NEW");
btnSubmit = new Button("SUBMIT");
btnView = new Button("VIEW");
btnNew.addActionListener(this);
btnSubmit.addActionListener(this);
btnView.addActionListener(this);
add(lblName);
add(txtName);
add(lblAge);
add(txtAge);
add(lblAddr);
add(txtAddr);
add(lblGender);
add(chkMale);
add(chkFemale);
add(lblcourse);
add(chkCS);
add(chkIT);
add(chkCOE);
add(chkBA);
add(btnNew);
add(btnSubmit);
add(btnView);
}
public void actionPerformed(ActionEvent ae)
{
String s="";
boolean b;
FileInputStream Fin;
DataInputStream dis;
FileOutputStream Fout;
DataOutputStream dos;
try
{
    Fout = new FileOutputStream("D:/Users/seifer/Desktop/Biodata.txt",true);
    dos = new DataOutputStream(Fout);
    String str = ae.getActionCommand();
    if(str.equals("SUBMIT"))
    {
        s=txtName.getText().trim();
        dos.writeUTF(s);
        s=txtAge.getText().trim();
        dos.writeUTF(s);
        s=txtAddr.getText();
        dos.writeUTF(s);
        if(chkMale.getState())
            dos.writeUTF("Male");
        if(chkFemale.getState())
            dos.writeUTF("Female");
        s="";
        if(chkCOE.getState())
            s="COE";
        if(chkCS.getState())
            s+="CS";
        if(chkIT.getState())
            s+="IT";
        if(chkBA.getState())
            s+="BA";
        s+="!";
        dos.writeUTF(s);
        Fout.close();
    }
    if(str.equals("VIEW"))
    {
        String tmp,name,age,addr,gender,course;

        Fin = new FileInputStream("D:/Users/seifer/Desktop/Biodata.txt");
        dis = new DataInputStream(Fin);
        int i=0,j;
        while(Fin.available()>0)
        {
            name = dis.readUTF();
            age  = dis.readUTF();
            addr = dis.readUTF();
            gender = dis.readUTF();
            course = dis.readUTF();
            if(name.equals(txtName.getText().trim()))
              {
                txtAge.setText(age+"");
                txtAddr.setText(addr);
                if(gender.equals("Male"))
                    chkMale.setState(true);
                else
                    chkFemale.setState(true);
                while(course.charAt(i)!='!')
                {
                    j=course.indexOf('!');
                    tmp = course.substring(i,j);
                    if(tmp.equals("COE"))
                        chkCOE.setState(true);
                    if(tmp.equals("CS"))
                        chkCS.setState(true);
                    if(tmp.equals("IT"))
                        chkIT.setState(true);
                    if(tmp.equals("BA"))
                        chkBA.setState(true);
                    i=j+1;
                }
                break;
            }
        }
        Fin.close();
    }
    if(str.equals("NEW"))
    {
        txtName.setText("");
        txtAge.setText("");
        txtAddr.setText("");
        chkMale.setState(false);
        chkFemale.setState(false);
        chkCOE.setState(false);
        chkCS.setState(false);
        chkIT.setState(false);
        chkBA.setState(false);
    }
}
catch(Exception e)
{
    System.out.println("The Exception Is : " +e);
    e.printStackTrace();
}
}
}
class Bio2
{
public static void main(String args[])
{
try{
Frame1 F = new Frame1("Biodata");
F.setSize(800,600);
F.show();
}catch(Exception e)
{
    System.out.println(e);
    e.printStackTrace();
}
}
}

this is confusing omg..

That code is not the code that you ran to get the exception stack trace. The line numbers are different. Just post to line that was line 125 when you ran the code.

sir james can you please fix this, its out of my league, i will study this after you fix it coz i need to make a documentation also.. please please

Sorry, no way. This is not a free "we do your homework" service. I try to help you learn what you need to know so you can do this yourself, but you have to do the work.
If you have been set this task by your tutor then (s)he obviously expects you to be able to do it. I won't be easy, but it will be possible.
Take a short break to clear your head, then start to debug this problem one step at a time, starting with the execption like I explained before.

this is the most recent error i get

   The Exception Is : java.io.EOFException
java.io.EOFException
at java.io.DataInputStream.readFully(DataInputStream.java:180)
at java.io.DataInputStream.readUTF(DataInputStream.java:592)
at java.io.DataInputStream.readUTF(DataInputStream.java:547)
at Frame1.actionPerformed(Frame1.java:105)
at java.awt.Button.processActionEvent(Button.java:392)
at java.awt.Button.processEvent(Button.java:360)
at java.awt.Component.dispatchEventImpl(Component.java:4660)
at java.awt.Component.dispatchEvent(Component.java:4488)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:674)
at java.awt.EventQueue.access$400(EventQueue.java:81)
at java.awt.EventQueue$2.run(EventQueue.java:633)
at java.awt.EventQueue$2.run(EventQueue.java:631)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:647)
at java.awt.EventQueue$3.run(EventQueue.java:645)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:644)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
most recent code:

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
class Frame1 extends Frame implements ActionListener
{
String msg="";
Button btnNew,btnSubmit,btnView;
Label lblName,lblAge,lblAddr,lblGender,lblcourse;
TextField txtName,txtAge;
TextArea txtAddr,txtAns;
CheckboxGroup ChkGrp;
Checkbox chkMale,chkFemale;
Checkbox chkCOE,chkCS,chkIT,chkBA;
 Frame1(String name)
{
super(name);
setLayout(new GridLayout(17,1));
lblName = new Label("Name: ");
lblAge = new Label("Age: ");
lblAddr = new Label("Address: ");
lblGender = new Label("Gender: ");
lblcourse = new Label("Course: ");
txtName = new TextField();
txtAge = new TextField();
txtAddr = new TextArea();
ChkGrp = new CheckboxGroup();
chkMale = new Checkbox("Male",ChkGrp,false);
chkFemale = new Checkbox("Female",ChkGrp,false);
chkCOE = new Checkbox("COE");
chkCS = new Checkbox("CS");
chkBA = new Checkbox("BA");
chkIT = new Checkbox("IT");
btnNew = new Button("NEW");
btnSubmit = new Button("SUBMIT");
btnView = new Button("VIEW");
btnNew.addActionListener(this);
btnSubmit.addActionListener(this);
btnView.addActionListener(this);
add(lblName);
add(txtName);
add(lblAge);
add(txtAge);
add(lblAddr);
add(txtAddr);
add(lblGender);
add(chkMale);
add(chkFemale);
add(lblcourse);
add(chkCS);
add(chkIT);
add(chkCOE);
add(chkBA);
add(btnNew);
add(btnSubmit);
add(btnView);
}
public void actionPerformed(ActionEvent ae)
{
String s="";
boolean b;
FileInputStream Fin;
DataInputStream dis;
FileOutputStream Fout;
DataOutputStream dos;
try
{
    Fout = new FileOutputStream("D:/Users/seifer/Desktop/Biodata.txt",true);
    dos = new DataOutputStream(Fout);
    String str = ae.getActionCommand();
    if(str.equals("SUBMIT"))
    {
        s=txtName.getText().trim();
        dos.writeUTF(s);
        s=txtAge.getText();
        dos.writeUTF(s);
        s=txtAddr.getText();
        dos.writeUTF(s);
        if(chkMale.getState())
            dos.writeUTF("Male");
        if(chkFemale.getState())
            dos.writeUTF("Female");
        s="";
        if(chkCOE.getState())
            s="COE";
        if(chkCS.getState())
            s+="CS";
        if(chkIT.getState())
            s+="IT";
        if(chkBA.getState())
            s+="BA";
        s+="!";
        dos.writeUTF(s);
        Fout.close();
    }
    if(str.equals("VIEW"))
    {
        String tmp,name,addr,gender,course;
         int age;
        Fin = new FileInputStream("D:/Users/seifer/Desktop/Biodata.txt");
        dis = new DataInputStream(Fin);
        int i=0,j;
        while(Fin.available()>0)
        {
            name = dis.readUTF();
            age  = dis.readInt();
            addr = dis.readUTF();
            gender = dis.readUTF();
            course = dis.readUTF();
            if(name.equals(txtName.getText().trim()))
              {
                txtAge.setText(age+"");
                txtAddr.setText(addr);
                if(gender.equals("Male"))
                    chkMale.setState(true);
                else
                    chkFemale.setState(true);
                while(course.charAt(i)!='!')
                {
                    j=course.indexOf('!');
                    tmp = course.substring(i,j);
                    if(tmp.equals("COE"))
                        chkCOE.setState(true);
                    if(tmp.equals("CS"))
                        chkCS.setState(true);
                    if(tmp.equals("IT"))
                        chkIT.setState(true);
                    if(tmp.equals("BA"))
                        chkBA.setState(true);
                    i=j+1;
                }
                break;
            }
        }
        Fin.close();
    }
    if(str.equals("NEW"))
    {
        txtName.setText("");
        txtAge.setText("");
        txtAddr.setText("");
        chkMale.setState(false);
        chkFemale.setState(false);
        chkCOE.setState(false);
        chkCS.setState(false);
        chkIT.setState(false);
        chkBA.setState(false);
    }
}
catch(Exception e)
{
    System.out.println("The Exception Is : " +e);
    e.printStackTrace();
}
}
}
class Bio2
{
public static void main(String args[])
{
try{
Frame1 F = new Frame1("Biodata");
F.setSize(800,600);
F.show();
}catch(Exception e)
{
    System.out.println(e);
    e.printStackTrace();
}
}
}

OK, that's the first readUTF (name), so now does this happen on the first record, the second record, or the last record? (You may need to add a print statement inside the read loop to show you what it's reading each time through)

what do you mean by record hehe no clue T_T

Verry sorry, but I have to go do some other stuff now. I'll check in on this thread later when I get back. Keep trying, don't give up.
J

anyone free, who can help me fix this?

What exactly have you tried in the last 3 hours? What debugging did you do? What were the results?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.