import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
public class DataDisplay extends JFrame{
    JTable table;
    public static JLabel jl1= new JLabel("Activity ID");
    public static JTextField jt1= new JTextField("Enter Activity ID");
    public static JLabel jl2= new JLabel("Activity name");
    public static JTextField jt2 = new JTextField("Enter Activity name");
    public static JLabel jl3= new JLabel("Start Date");
    public static JTextField jt3= new JTextField("Enter Start Date");
    public static JLabel jl4 = new JLabel("End Date");
    public static JTextField jt4= new JTextField("Enter End Date");
    public static JLabel jl5 = new JLabel("Alarm Before");
    public static JTextField jt5= new JTextField("enter alarm");
    public static JLabel jl= new JLabel("HOURS");
    public static JButton save = new JButton("SAVE");
    public static JButton close = new JButton("CLOSE");
    public Container c= this.getContentPane();
    private static int counter=0;
    DataDisplay(){
        this.setTitle("Assignment 3");
        this.setLayout(null);
        this.setBackground(Color.MAGENTA);
        c.add(jl1);
        c.add(jt1);
        c.add(jl2);
        c.add(jt2);
        c.add(jl3);
        c.add(jt3);
        c.add(jl4);
        c.add(jt4);
        c.add(jl5);
        c.add(jt5);
        c.add(jl);
        jl1.setBounds(10, 10, 100, 100);
        jt1.setBounds(100, 45, 100, 30);
        jl2.setBounds(10,60,100,100);
        jt2.setBounds(100,100,120,30);
        jl3.setBounds(10,110,100,100);
        jt3.setBounds(100,145,120,30);
        jl4.setBounds(10,160,100,100);
        jt4.setBounds(100,200,120,30);
        jl5.setBounds(10,210,100,100);
        jt5.setBounds(100,250,120,30);
        jl.setBounds(230,210,100,100);
        c.add(save);
        save.setBounds(10,300,100,30);
        save.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent arg0) {
                int ce=0;
                // TODO Auto-generated method stub
                String tableHeader[] ={"Activity ID", "Activity name", "Start Date", "End Date","Alarm before (Hours)"};
                String tableData[][]= new String[ce=counter+1][10];
                table = new JTable(tableData, tableHeader);
                String line=null;
                BufferedReader b=null;
                try {
                    b = new BufferedReader(new FileReader("Activity.txt"));
                } catch (FileNotFoundException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                try {
                    int row=0,col=0;
                    while ((line=b.readLine())!=null){
                        String[] s= new String[100];
                        for(int counterc=1; counterc<=4; counterc++ ){//*ARRAY OUT OF BOUND EXCEPTION*
                         s=line.split("|",4);
                        }
                            tableData[row][0]=s[0];
                            tableData[row][1]=s[1];
                            tableData[row][2]=s[2];
                            tableData[row][3]=s[3];
                        row++;
                }} catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                finally{
                    try {
                        b.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                tableData[counter][0]=jt1.getText();
                tableData[counter][1]=jt2.getText();
                tableData[counter][2]=jt3.getText();
                tableData[counter][3]=jt4.getText();
                tableData[counter][4]=jt5.getText();
                JScrollPane scrollPane = new JScrollPane(table);
                c.add(scrollPane, BorderLayout.CENTER);
                scrollPane.setBounds(10, 400, 700, 600);
                counter++;
                try{
                    FileWriter out= new FileWriter("Activity.txt",true);
                    BufferedWriter br= new BufferedWriter(out);
                    PrintWriter p= new PrintWriter(br);
                    p.println(jt1.getText()+"|"+jt2.getText()+"|"+jt3.getText()+"|"+jt4.getText()+"|"+jt5.getText());
                    p.close();
                }
                catch(IOException e){
                    e.getStackTrace();
                }
            }
        });
        c.add(close);
        close.setBounds(200,300,100,30);
        this.setBounds(100,100,1000,1000);
        this.setVisible(true);
        c.setVisible(true);
    }
    public static void main(String args[]){
        DataDisplay dd= new DataDisplay();
    }
}
Here's my code. Only the last entered line in table is being displayed not the initial lines. I also used while(readline != null) but that gives either null pointer exception or array out of bounds exception. So what condition should I put in while loop?
 
     
     
     
     
     
    