?
Solved

java.lang.StackOverflowError

Posted on 2005-03-26
23
Medium Priority
?
424 Views
Last Modified: 2012-06-21
Hi,
I am working on a GUI application. What could i check if i am having *java.lang.StackOverflowError*
error message. That is all i am getting as error message. For this reason, my GUI compenent are NOT being displayed.
0
Comment
Question by:komlaaa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 5
  • 2
  • +3
23 Comments
 
LVL 92

Expert Comment

by:objects
ID: 13637785
generally caused by recursion gone wrong, ie. an endless loop in the call stack.
the stack trace should give you a good clue where it is occurring
0
 

Author Comment

by:komlaaa
ID: 13637793
>>the stack trace should give you a good clue where it is occurring
all i am getting printed on my screen is: java.lang.StackOverflowError.
Thats hard to know where that occured
0
 
LVL 92

Expert Comment

by:objects
ID: 13637808
can you post your code
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:komlaaa
ID: 13637840
king of long though, but i think the problem is at architecture and constructors level

============== MAIN CLASS ============
public class StudentSupportServices extends JFrame
{
    private StudentPanel studentPanel;
    private CoursePanel coursePanel;
    private JPanel studentCourseProfessorExamPanel;
    private ProfessorPanel professorPanel;
    private ExamPanel examPanel;
    private ControlPanel controls;
    private String url;
    private JTextArea output;
    private Connection accessCon;// = null;
    private Container c;
   
    /** Creates a new instance of StudentInformations */
    public StudentSupportServices( )
    {
     
        super("Student Support Services");
        if (!startApplication() ) System.exit(0);

        c = getContentPane();
        JMenuBar menuBar = new JMenuBar();
        JMenu fileMenu = new JMenu("File");
        fileMenu.add(new RenewDatabase());
       
        menuBar.add( fileMenu );
        setJMenuBar(menuBar);
       
        output = new JTextArea();
        output.setEditable(false);
               
         setDefaultCloseOperation( EXIT_ON_CLOSE );

         try
        {
         //Connect to ess database.  
            url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" +
            "C:/accessDb/Students.mdb";
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            accessCon = DriverManager.getConnection( url );
            output.append("Connection successful\n");
         
        }
     
        catch( SQLException sqlex )
        {
            //process SQLException
            sqlex.printStackTrace();
            output.append("Connection Uncessful\n" + sqlex.toString() );
        }
          catch( Exception ex )
        {
            //process remaining Exception here
            ex.printStackTrace();
            output.append( ex.toString() );
        }
      //  course = new CoursePanel();
        studentPanel = new StudentPanel( accessCon );
        professorPanel = new ProfessorPanel();
       
        JPanel StudentProfessorPanel = new JPanel();
        StudentProfessorPanel.setLayout(new GridLayout(1,2));
        StudentProfessorPanel.add( studentPanel );
        StudentProfessorPanel.add( professorPanel );
     
         
        studentCourseProfessorExamPanel = new JPanel();
        studentCourseProfessorExamPanel.setLayout( new GridLayout(3,1) );
        studentCourseProfessorExamPanel.add( StudentProfessorPanel );  
       
        coursePanel = new CoursePanel(this, studentPanel, accessCon);
        studentCourseProfessorExamPanel.add( coursePanel );
       
        examPanel = new ExamPanel(this, coursePanel, accessCon);
        studentCourseProfessorExamPanel.add( examPanel );

        c.setLayout( new BorderLayout() );
        c.add( studentCourseProfessorExamPanel, BorderLayout.CENTER ) ;
       
        controls = new ControlPanel(coursePanel, examPanel,
                                                professorPanel, studentPanel);
        c.add( controls, BorderLayout.NORTH );
        c.add( output, BorderLayout.SOUTH );
       
        pack();
        show();
    }///////////////////// END OF CONSTRUCTOR

  //tells the user the state of any request
   public void setQueryInfo(String text)
   {
       output.setText("");
       output.append( text );
   }
   
     
   public void showErrorMessages( String err )
   {
       
       Toolkit.getDefaultToolkit().beep();
       JOptionPane.showMessageDialog(this,err, "Error",
       JOptionPane.ERROR_MESSAGE );
       return;

   }
   
   //check if there is a compenent on the panel already.
   //if yes, remove it and place a the current one.
   public void displayCourseTable( ResultSet rs, JTable table )
   {
       
       if( coursePanel.getComponentCount() > 0 )
           coursePanel.removeAll();
       
       try{
           displayJTables( rs, table, "No courses found.");
          }
       catch(SQLException sqlex )
       {
          sqlex.printStackTrace();
       }
       
       //these two columns should be displayed to the user.
        table.removeColumn( table.getColumnModel().getColumn( 0 ) );
        table.removeColumn( table.getColumnModel().getColumn( 4 ) );
       
        table.getColumnModel().getColumn( 4 ).setPreferredWidth( 200 );
       
       JScrollPane scroller  = new JScrollPane( table );
       coursePanel.add( scroller );
       
   }
   
   public void displayExamsTable(ResultSet rs, JTable table)
   {
               
    try{
           displayJTables( rs, table, "No courses found.");
       }
       catch(SQLException sqlex )
       {
           sqlex.printStackTrace();
       }  
       
        /**these two columns should be displayed to the user.:
         * ===> remove them from the table view
         *Note that after removing the first column,
         *the column which was at index 1, is shifted
         *to index 0:====> remove at index 0 twice.
         */
        table.removeColumn( table.getColumnModel( ).getColumn(0) );
        table.removeColumn( table.getColumnModel( ).getColumn(0) );

        table.getColumnModel().getColumn(6).setPreferredWidth(200);
               
        JScrollPane scroller  =  new JScrollPane( table );
        examPanel.add( scroller );

   }
   

  public Vector getNextRow(ResultSet rs, ResultSetMetaData meta)
   throws SQLException
{
    Vector currentRow = new Vector();
    for(int i = 1; i <= meta.getColumnCount(); i++)
   
        switch(meta.getColumnType(i) )
        {
            case Types.DOUBLE:
            {
                double x = rs.getDouble(i);
                int u = (int)x;
               
                currentRow.addElement( u + "" );
                 break;
            }
            case Types.VARCHAR:
            case Types.LONGVARCHAR:
                currentRow.addElement(rs.getString(i) );
                break;
            case Types.INTEGER:
                currentRow.addElement( new Long( rs.getLong( i )) );
                break;
           case Types.DATE:
                currentRow.addElement( rs.getDate( i ) );
                break;
            case Types.TIME:
                 currentRow.addElement(rs.getTime( i ) );
                 break;
        case Types.TIMESTAMP:
             currentRow.addElement(rs.getTimestamp( i ) );
                break;
        case Types.OTHER:
        case Types.JAVA_OBJECT:
             currentRow.addElement(rs.getObject( i ) );
              break;
        }
   
        return currentRow;
}

      /////////////////// display exams
     public void displayJTables( ResultSet rs, JTable table, String err )
     throws SQLException
     {
            //position to first record
             boolean moreRecords = rs.next();
             
             //if there is no records, display a message
             if( !moreRecords )
             {
                 showErrorMessages( err );
                 
             }
             
             Vector columnHeads = new Vector();
             Vector rows = new Vector();
           
         try
         {    
            //get column heads
             ResultSetMetaData rsmd = rs.getMetaData();
             for( int i = 1; i <= rsmd.getColumnCount(); ++i )
                 columnHeads.addElement( rsmd.getColumnName( i ) );
             
             //get row data
             do {
                rows.addElement( getNextRow(rs, rsmd) );
            }while( rs.next() );
          table.setModel( new DefaultTableModel(rows, columnHeads) );
         
          }
         catch (SQLException sqlex )
         {
             sqlex.printStackTrace();
         }
             
         
     }
....

  /////////////         MAIN      ////////////////////////////////    
        public static void main( String [] args )
        {
           new StudentSupportServices();
        }

}//END OF MAIN CLASS

===================== CLASS CoursePanel ===============
public class ControlPanel extends JPanel

{
    private JButton findCourse,findExam, addData, updateData, refresh, help;
    private CoursePanel coursePanel;
    private ExamPanel examPanel;
    private ProfessorPanel professorPanel;
    private StudentPanel studentPanel;
   
   
    /** Creates a new instance of ControlPanel */
    public ControlPanel(CoursePanel coursePanel, ExamPanel examPanel,
                       ProfessorPanel professorPanel, StudentPanel studentPanel)
                   
    {
        super();
        setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
        setBorder(new CompoundBorder(
        BorderFactory.createLineBorder(Color.BLACK,1),
        BorderFactory.createBevelBorder(BevelBorder.RAISED)));
       
        this.coursePanel = coursePanel;
        this.examPanel = examPanel;
        this.studentPanel = studentPanel;
        this.professorPanel = professorPanel;
       
        /**================= refresh the GUI ==================================*/
        refresh = new JButton("Refresh");
        new ImageIcon( getClass().getResource("images/Refresh24.gif") );
        refresh.setMnemonic('R');
        refresh.addActionListener
        (
            new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    refreshGUI();
                }
            }
        );
       add(refresh);
       
        /**================= find courses ==================================*/
        findCourse = new JButton( "Get Courses",
        new ImageIcon(getClass().getResource("images/Bookmarks24.gif")));
        findCourse.setMnemonic('C');
        //add actionListner later
        findCourse.addActionListener
        (
            new ActionListener()
            {
                public void actionPerformed( ActionEvent e)
                {
                    if(findCourse == e.getSource() )
                    displayCourseTable();
                }
            }
        );
        add( findCourse );
       
        /**================= find Exams ==================================*/
        findExam = new JButton( "Get Exams",
        new ImageIcon(getClass().getResource("images/Edit24.gif")));
        findExam.setMnemonic('E');
        /**add actionListner */
        findExam.addActionListener
        (
            new ActionListener()
            {
                public void actionPerformed( ActionEvent e)
                {
                    if( findExam == e.getSource() )
                    displayExamTable();
                }
            }
        );
        add(findExam);
         
        /**================= add new Student ===============================*/
         addData = new JButton( "Add New Student",
        new ImageIcon(getClass().getResource("images/Add24.gif")));
        //add actionListner later
        //addData.addActionListener( new AddRecord(con, s, p, c, e) );
        add( addData );
        addData.setMnemonic('S');
       
        /**================= update Student info =============================*/
        updateData = new JButton( "Save",
        new ImageIcon(getClass().getResource("images/Save24.gif")));
        //add actionListner later
        add(updateData);
        updateData.setMnemonic('s');
                 
        help = new JButton( "Help",
        new ImageIcon(getClass().getResource("images/Help24.gif")));
        //add actionListner later
        add(help);
        help.setMnemonic('H');
    }
   
    private void displayCourseTable()
    {
       coursePanel.populateCourseTable();
    }
   
    private void displayExamTable()
    {
        examPanel.populateExamTable();
    }
   
    private void refreshGUI()
    {
        studentPanel.clearSutdentPanel();
        professorPanel.clearProfessorPanel();
       
        coursePanel.initCourseTable();
        examPanel.initExamsTable();
       
        studentPanel.refreshCombo();
    }
   
}
================= CLASS MyPanelModel ================
public abstract class MyPanelModel extends JPanel
{
   
    /** Creates a new instance of MyPanelModel
     *will be used as parent panel to initialize studentPanel, professorPanel
     *coursePanel, examsPanel
     */
    public MyPanelModel( String panelTitle )
    {
        super();
        setLayout( new BorderLayout() );
        setBorder(new TitledBorder(new EtchedBorder(), panelTitle));    
    }
   
}

================= CLASS ExamPanel ================
public class ExamPanel extends MyPanelModel
{

    private JTable examsTable;
    private Connection connection;
    private CoursePanel coursePanel;
    private ProfessorPanel professorPanel;
    private StudentSupportServices sss;
   
    /** Creates a new instance of ExamTable */
    public ExamPanel(StudentSupportServices sss, CoursePanel coursePanel,
                                                        Connection connection)
    {
        super("Exams");
        setLayout( new BorderLayout() );
       
        this.connection = connection;
        this.coursePanel = coursePanel;
        this.connection = connection;
        this.sss = sss;
       
        initExamsTable();
    }
   
    /**initialize examsTale */
    public void initExamsTable()
    {
         examsTable = new JTable(new DefaultTableModel(
     new Object [][]{ {"", "", "", "", "", "",""},
     {"", "", "", "", "", "",""},{"", "", "", "", "", "",""},
     {"", "", "", "", "", "",""}, {"", "", "", "", "", "",""},
     {"", "", "", "", "", "",""} },
        new Object[]{"Date", "Time", "Time In", "Time Out",
      "Delivred by", "Total Time","Special Instruction"}) );
     
      JScrollPane examScroll = new JScrollPane ( examsTable );  
    }
   
    //popublate examsTable based on the course selected
    public void populateExamTable()
    {
        int cID = 0;
        int profID = 0;
           //cehck to see if there is a compenent on panel already. If yes, remove it
            // and place a new one.
             if( this.getComponentCount() > 0 )
              this.removeAll();
             
            if(coursePanel.getComponentCount() > 0 )
            {
                if( coursePanel.getSelectedRowCount() == 1 )
                {
                    //these value are being retrieved from the Tablemodel not from the visible table.
                cID = coursePanel.getCourseID();
                profID = coursePanel.getProfessorID();
            }
            else
            {      
                sss.showErrorMessages("You must first select a course.");
                return;
            }
       }
      else
      {
          sss.showErrorMessages("1.)Find the couses\n 2.) select the a course\n" +
          "3.) And find the exams for that course.");

      }  

             System.out.println("class Num:" + cID);
             System.out.println("profID: " + profID);
             
             Statement profStm = null;
             Statement examStm = null;
             ResultSet profRs = null;
             ResultSet examRs = null;
     
             try{
                 profStm = connection.createStatement();
                 examStm = connection.createStatement();
                 
                 profRs = profStm.executeQuery("SELECT * FROM professor WHERE "+
                "professorID ="  + profID + ";");
                 
                 examRs = examStm.executeQuery("SELECT * FROM Exam WHERE CourseID" +
                 "=" + cID +";");
                 
                professorPanel.displayProfessor( profRs,  profID );
               
                sss.displayExamsTable( examRs, examsTable);
               
                sss.setQueryInfo( "\nQuery Successful" );
         
        }
        catch ( SQLException sqlex )
          {
             sqlex.printStackTrace();
          }
            finally
            {
                try
                {
                    if( profStm != null ) profStm.close();
                    if( examStm != null ) examStm.close();
//                   if( profRs != null )  profRs.close();
               //    if( examRs != null ) examRs.close();
                }
                catch (SQLException sqlex)
                {
                    sqlex.printStackTrace();
                }
            }
       
     }
   
    }//end of Class ExamPanel

================= CLASS CoursePanel ================
follow same logic as ExamPanel above

================= CLASS StudentPanel ================
public class StudentPanel extends MyPanelModel
implements ActionListener
{
 private final JTextField firstField, idField, phoneField, boxField, accomField;
 private final JComboBox lastCombo;
 private JPanel fields ;
 private Connection connection;

 
    /** Creates a new instance of StudentPanel */
    public StudentPanel(Connection connection)
    {
         super("Student");
         this.connection = connection;
     
         JPanel labels = new JPanel();
         labels.setLayout( new GridLayout(6,1,0,3) );
           
         JLabel lastLabel = new JLabel("Last Name: ", SwingConstants.RIGHT);
         JLabel firstLabel = new JLabel("First Name: ", SwingConstants.RIGHT);
         JLabel idLabel = new JLabel("Student Num: ", SwingConstants.RIGHT);
         JLabel phoneLabel = new JLabel("Phone #: ", SwingConstants.RIGHT);
         JLabel boxLabel = new JLabel("Box #: ", SwingConstants.RIGHT);          
         JLabel accomLabel = new JLabel("Accomodation: ", SwingConstants.RIGHT);          
         
         labels.add(lastLabel );
         labels.add( firstLabel);
         labels.add(idLabel );
         labels.add(phoneLabel );
         labels.add( boxLabel );
         labels.add( accomLabel);
         
         fields = new JPanel();
         fields.setLayout( new GridLayout(6,1,0,3) );
         lastCombo = new JComboBox( );
         
         lastCombo.addActionListener(this );//
        // lastCombo.addItemListener(this);
         
         lastCombo.setEditable(true);
         firstField = new JTextField( ) ;
         //firstField.setEditable(true);

         idField  = new JTextField();
         phoneField = new JTextField(5);
         boxField = new JTextField(5);
         accomField = new JTextField();
         
         fields.add( lastCombo );
         fields.add( firstField );
         fields.add(idField );
         fields.add(phoneField );
         fields.add( boxField );
         fields.add( accomField);
         
         add( labels, BorderLayout.WEST);
         add(fields, BorderLayout.CENTER);

}
 
 
public void actionPerformed(ActionEvent event)
{
    Statement studentStm = null;
    ResultSet rs = null;
         if (connection==null) {
            System.out.println("You are missing a connection to the database");
         }
         String last = ((String)lastCombo.getSelectedItem()).trim();
         System.out.println("Last Name: " + last);
         if(last.length() !=0 )    // would this actually occur?
         {
         try{
                studentStm = connection.createStatement();                
                rs = studentStm.executeQuery("SELECT * FROM Student" +
                 " WHERE [Last Name] = '" + last + "';");
                displayStudent(rs);
            }
            catch( SQLException sqlex )
            {
               sqlex.printStackTrace();
            }
         
            finally
            {
               try
               {
                 if (studentStm!=null) studentStm.close();
                 if (rs!=null) rs.close();
               }
               catch( SQLException sqlex )
               {
                  //sqlex.printStackTrace();
               }
         }
}
    }/////////////end of actionPerformed()


    //display query result if not rs not null.
     public void displayStudent( ResultSet rs )
     {
         int sId = 0;
       try{
             if( rs.next() )
                {
                   sId = rs.getInt( 1 );
                   
                }
             System.out.println("Student id2:" +  sId);
         if( sId != 0 )
         {
             lastCombo.setSelectedItem( rs.getString( 2 ) );
             firstField.setText( rs.getString( 3 ) );
             idField.setText( rs.getString( 4 ) );
              phoneField.setText( rs.getString( 5 ) );
              boxField.setText( rs.getString( 6 ) );
              accomField.setText(rs.getString( 7 ) );
         }
         else
         {
           ;//  sss.setQueryInfo( " No record Found\n");
           
         }
        }
         catch( SQLException sqlex )
         {
             sqlex.printStackTrace();
         }
     
     }// end of displayStudent( ).
 
     
    //assign a new dataModel to the comboBox.
     public void refreshCombo()
    {
        Statement s = null;
        ResultSet rs  = null;
       
        try
       {
                s = connection.createStatement();
                rs = s.executeQuery("SELECT [Last Name] FROM Student");

             //  Vector firstNames = new Vector();
               Vector lastNames = new Vector();
               lastNames.addElement("-- SELECT --");

                while( rs.next() )
                {
                    lastNames.addElement( rs.getString("Last Name") );
                 }
                lastCombo.setModel( new DefaultComboBoxModel(lastNames) );
 
               s.close();
 
       }
       catch (SQLException sqlex)
       {
           sqlex.printStackTrace();
       }
         
    }
       
       //return last name
    public String getLast()
    {
       
            return ((String)lastCombo.getSelectedItem()).trim();
    }
   
    //return first name
    public String getFirst()
    {
       
        return ( (String)firstField.getText()).trim();
    }
   
    //return student num
    public String getStudentNum()
    {
        return ( (String)idField.getText() ).trim();
    }

    //return phone #
    public String getPhoneNum()
    {
        return ( (String)phoneField.getText() ).trim();
    }
   
    //return Box num
    public String getBoxNum()
    {
        return ( (String)boxField.getText() ).trim();
    }
   
    public String getAccom()
    {
        return ( (String)accomField.getText() ).trim();
    }
   
    public void setLastName( String text )
    {
        lastCombo.setSelectedItem( text );
    }
   
    public void setFirstName ( String text )
    {
        firstField.setText( text );
    }
   
    public void setStudentNum ( String text )
    {
        idField.setText( text );
    }
   
    public void setPhoneNum ( String text )
    {
       phoneField.setText( text );
    }
   
    public void setBoxNum ( String text )
    {
        boxField.setText( text );
    }
   
    public void setAccom ( String text )
    {
        accomField.setText( text );
    }
   
   public void clearSutdentPanel()
   {
       for(int i = 1; i < fields.getComponentCount(); i++ )
           ((JTextField)fields.getComponent(i)).setText("");

   }
 
}
================= CLASS ProfessorPanel ================
follow same logic as StudentPanel above
================= CLASS ControlPanel =================
public class ControlPanel extends JPanel

{
    private JButton findCourse,findExam, addData, updateData, refresh, help;
    private CoursePanel coursePanel;
    private ExamPanel examPanel;
    private ProfessorPanel professorPanel;
    private StudentPanel studentPanel;
   
   
    /** Creates a new instance of ControlPanel */
    public ControlPanel(CoursePanel coursePanel, ExamPanel examPanel,
                       ProfessorPanel professorPanel, StudentPanel studentPanel)
                   
    {
        super();
        setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
        setBorder(new CompoundBorder(
        BorderFactory.createLineBorder(Color.BLACK,1),
        BorderFactory.createBevelBorder(BevelBorder.RAISED)));
       
        this.coursePanel = coursePanel;
        this.examPanel = examPanel;
        this.studentPanel = studentPanel;
        this.professorPanel = professorPanel;
       
        /**================= refresh the GUI ==================================*/
        refresh = new JButton("Refresh");
        new ImageIcon( getClass().getResource("images/Refresh24.gif") );
        refresh.setMnemonic('R');
        refresh.addActionListener
        (
            new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    refreshGUI();
                }
            }
        );
       add(refresh);
       
        /**================= find courses ==================================*/
        findCourse = new JButton( "Get Courses",
        new ImageIcon(getClass().getResource("images/Bookmarks24.gif")));
        findCourse.setMnemonic('C');
        //add actionListner later
        findCourse.addActionListener
        (
            new ActionListener()
            {
                public void actionPerformed( ActionEvent e)
                {
                    if(findCourse == e.getSource() )
                    displayCourseTable();
                }
            }
        );
        add( findCourse );
       
        /**================= find Exams ==================================*/
        findExam = new JButton( "Get Exams",
        new ImageIcon(getClass().getResource("images/Edit24.gif")));
        findExam.setMnemonic('E');
        /**add actionListner */
        findExam.addActionListener
        (
            new ActionListener()
            {
                public void actionPerformed( ActionEvent e)
                {
                    if( findExam == e.getSource() )
                    displayExamTable();
                }
            }
        );
        add(findExam);
         
        /**================= add new Student ===============================*/
         addData = new JButton( "Add New Student",
        new ImageIcon(getClass().getResource("images/Add24.gif")));
        //add actionListner later
        //addData.addActionListener( new AddRecord(con, s, p, c, e) );
        add( addData );
        addData.setMnemonic('S');
       
        /**================= update Student info =============================*/
        updateData = new JButton( "Save",
        new ImageIcon(getClass().getResource("images/Save24.gif")));
        //add actionListner later
        add(updateData);
        updateData.setMnemonic('s');
                 
        help = new JButton( "Help",
        new ImageIcon(getClass().getResource("images/Help24.gif")));
        //add actionListner later
        add(help);
        help.setMnemonic('H');
    }
   
    private void displayCourseTable()
    {
       coursePanel.populateCourseTable();
    }
   
    private void displayExamTable()
    {
        examPanel.populateExamTable();
    }
   
    private void refreshGUI()
    {
        studentPanel.clearSutdentPanel();
        professorPanel.clearProfessorPanel();
       
        coursePanel.initCourseTable();
        examPanel.initExamsTable();
       
        studentPanel.refreshCombo();
    }
   
}
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13638134
Can you add System.out.println(....)
in StudentSupportServices before the creation
of each one of your classes (StudentSupportServices, ProfessorPanel, CoursePanel, ...)
That will help to isolate your problem.
0
 

Author Comment

by:komlaaa
ID: 13638252
i actually did. I was able to print
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13638264
I didn't see it in your code.
Did you post the println results?
If so, where is the last line of println
before you got StackOverflow exception?
0
 

Author Comment

by:komlaaa
ID: 13638272
>>I didn't see it in your code.
I did in most recent version
The GUI is displayed. All the component are there but i have to click on each one before i can see them,... strange.
.....
            //process remaining Exception here
            ex.printStackTrace();
            output.append( ex.toString() );
        }
      //  course = new CoursePanel();
        studentPanel = new StudentPanel( accessCon );
        professorPanel = new ProfessorPanel();
       
        JPanel StudentProfessorPanel = new JPanel();
        StudentProfessorPanel.setLayout( new GridLayout(1,2) );
        StudentProfessorPanel.add( studentPanel );
        StudentProfessorPanel.add( professorPanel );
     
         
        studentCourseProfessorExamPanel = new JPanel();
        studentCourseProfessorExamPanel.setLayout( new GridLayout(3,1) );
        studentCourseProfessorExamPanel.add( StudentProfessorPanel );  
        System.out.println("before StudentPanle");
        coursePanel = new CoursePanel(this, studentPanel, accessCon);
        studentCourseProfessorExamPanel.add( coursePanel );
       
        System.out.println("before ExamPanel");
        examPanel = new ExamPanel(this, coursePanel, accessCon);
        studentCourseProfessorExamPanel.add( examPanel );

        c.setLayout( new BorderLayout() );
        c.add( studentCourseProfessorExamPanel, BorderLayout.CENTER ) ;
        System.out.println("before controPanle");
        controlPanel = new ControlPanel(coursePanel, examPanel,
                                                professorPanel, studentPanel);
        c.add( controlPanel, BorderLayout.NORTH );
        System.out.println("after controPanle");
        c.add( output, BorderLayout.SOUTH );
       
        pack();
        show();
    }///////////////////// END OF CONSTRUCTOR
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13638292
Does the exception come after all the printouts?
0
 

Author Comment

by:komlaaa
ID: 13638295
>Does the exception come after all the printouts?
yes
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13638310
Never tried to see what happens when you
add a container (panel) to a container which is
already its child. If java does not dectect such error during the add operation then that might lead to infinte recursion during the presentation.
0
 

Author Comment

by:komlaaa
ID: 13638328
>Never tried to see what happens when you
>add a container (panel) to a container which is
>already its child
Where do you mean? where did i do that?
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13638349
Just rasing a posibility though I could not find it in your code so far.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 13639168
You are printing the stack-trace of all exceptions, I guess. Were you not able to catch which line it occurs at? (Check your console.)
0
 

Author Comment

by:komlaaa
ID: 13639205
>Were you not able to catch which line it occurs at?
all i am geting prited on my srcreen is *java.lang.StackOverflowError* JUST THAT otherwise i could have fixed it.
0
 

Author Comment

by:komlaaa
ID: 13639218
Also all the components appeared on my main Frame but i have click on each one before they become visible.
0
 
LVL 6

Expert Comment

by:cjard
ID: 13639219
are you running this code in an ide? try running it from the command line so we get a proper stack trace out of it, and post..
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 13639237
1. You may try to comment out all the database stuffs, and try if there is still StackOverFlowError.
2. If StackOverFlowError still occurs, try to isolate each component by adding one component at a time.

Since the program is very long for others to trace, please try my suggestion to get your problem easier to be solved.
0
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 1500 total points
ID: 13639250
The reason for only visible after clicking buttons are you are trying to add the components inside your actionlisteners of the buttons.
If this is not your intension, you need to call the displayXXX inside your constructor.
0
 

Author Comment

by:komlaaa
ID: 13639760
>>The reason for only visible after clicking buttons are you are trying to add the components inside your actionlisteners >>of the buttons.If this is not your intension, you need to call the displayXXX inside your constructor.
I think u r right. The StackOverFlowError is gonne but then i am running into NullPointerException eventhough i have initialized all my constructor before using them:

java.lang.NullPointerException
        at sss2.StudentPanel.getLast(StudentPanel.java:194)
        at sss2.CoursePanel.populateCourseTable(CoursePanel.java:67)
        at sss2.ControlPanel.displayCourseTable(ControlPanel.java:125)
        at sss2.ControlPanel.<init>(ControlPanel.java:119)
        at sss2.StudentSupportServices.<init>(StudentSupportServices.java:108)
        at sss2.StudentSupportServices.main(StudentSupportServices.java:796)
0
 

Author Comment

by:komlaaa
ID: 13639858
================ New Version of Contropanel ==========
public class ControlPanel extends JPanel

{
    private JButton findCourse,findExam, addData, updateData, refresh, help;
    private CoursePanel coursePanel;
    private ExamPanel examPanel;
    private ProfessorPanel professorPanel;
    private StudentPanel studentPanel;
   
   
    /** Creates a new instance of ControlPanel */
    public ControlPanel(CoursePanel coursePanel, ExamPanel examPanel,
                       ProfessorPanel professorPanel, StudentPanel studentPanel)
                   
    {
        super();
        setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
      //  setBorder(new CompoundBorder(
       // BorderFactory.createLineBorder(Color.BLACK,1),
       // BorderFactory.createBevelBorder(BevelBorder.RAISED)));
       
        this.coursePanel = coursePanel;
        this.examPanel = examPanel;
        this.studentPanel = studentPanel;
        this.professorPanel = professorPanel;
       
        System.out.println("before refresh");
        /**================= refresh the GUI ==================================*/
        refresh = new JButton("Refresh",
       new ImageIcon( getClass().getResource("images/Refresh24.gif") ));
         refresh.setMnemonic('R');
        refresh.addActionListener
        (
            new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    refreshGUI();
                }
            }
        );
       add(refresh);
       
        System.out.println("before findCourse");
        /**================= find courses ==================================*/
        findCourse = new JButton( "Get Courses",
        new ImageIcon(getClass().getResource("images/Bookmarks24.gif")));
        findCourse.setMnemonic('C');
        //add actionListner later
        findCourse.addActionListener
        (
            new ActionListener()
            {
                public void actionPerformed( ActionEvent e)
                {
                    if(findCourse == e.getSource() )
                    displayCourseTable();
                }
            }
        );
        add( findCourse );
        System.out.println("before findExam");
        /**================= find Exams ==================================*/
        findExam = new JButton( "Get Exams",
        new ImageIcon(getClass().getResource("images/Edit24.gif")));
        findExam.setMnemonic('E');
        /**add actionListner */
        findExam.addActionListener
        (
            new ActionListener()
            {
                public void actionPerformed( ActionEvent e)
                {
                    if( findExam == e.getSource() )
                    displayExamTable();
                }
            }
        );
        add(findExam);
          System.out.println("before add new Student");
        /**================= add new Student ===============================*/
         addData = new JButton( "Add New Student",
        new ImageIcon(getClass().getResource("images/Add24.gif")));
        //add actionListner later
        //addData.addActionListener( new AddRecord(con, s, p, c, e) );
        add( addData );
        addData.setMnemonic('S');
       
        /**================= update Student info =============================*/
        updateData = new JButton( "Save",
        new ImageIcon(getClass().getResource("images/Save24.gif")));
        //add actionListner later
        add(updateData);
        updateData.setMnemonic('s');
                 
        help = new JButton( "Help",
        new ImageIcon(getClass().getResource("images/Help24.gif")));
        //add actionListner later
        add(help);
        help.setMnemonic('H');
       
       displayCourseTable();
       displayExamTable();
    }
   
    private void displayCourseTable()
    {
       coursePanel.populateCourseTable();
    }
   
    private void displayExamTable()
    {
        examPanel.populateExamTable();
    }
   
    private void refreshGUI()
    {
        studentPanel.clearSutdentPanel();
        professorPanel.clearProfessorPanel();
       
        coursePanel.initCourseTable();
        examPanel.initExamsTable();
       
        studentPanel.refreshCombo();
    }
   
}
===========StudentSupportServices============
public StudentSupportServices( )
    {
     
        super("Student Support Services");
        if (!startApplication() ) System.exit(0);

        c = getContentPane();
        c.setLayout( new BorderLayout() );
        JMenuBar menuBar = new JMenuBar();
        JMenu fileMenu = new JMenu("File");
        fileMenu.add(new RenewDatabase());
       
        menuBar.add( fileMenu );
        setJMenuBar(menuBar);
       
        output = new JTextArea();
        output.setEditable(false);
               
         setDefaultCloseOperation( EXIT_ON_CLOSE );

         try
        {
         //Connect to ess database.  
            url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" +
            "C:/accessDb/Students.mdb";
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            accessCon = DriverManager.getConnection( url );
            output.append("Connection successful\n");
         
        }
     
        catch( SQLException sqlex )
        {
            //process SQLException
            sqlex.printStackTrace();
            output.append("Connection Uncessful\n" + sqlex.toString() );
        }
          catch( Exception ex )
        {
            //process remaining Exception here
            ex.printStackTrace();
            output.append( ex.toString() );
        }
     
         
        studentPanel = new StudentPanel( accessCon );
        professorPanel = new ProfessorPanel();
       
        JPanel StudentProfessorPanel = new JPanel();
        StudentProfessorPanel.setLayout( new GridLayout(1,2) );
        StudentProfessorPanel.add( studentPanel );
        StudentProfessorPanel.add( professorPanel );
     
         
        studentCourseProfessorExamPanel = new JPanel();
        studentCourseProfessorExamPanel.setLayout( new GridLayout(3,1) );
        studentCourseProfessorExamPanel.add( StudentProfessorPanel );  
        coursePanel = new CoursePanel(this, studentPanel, accessCon);
        studentCourseProfessorExamPanel.add( coursePanel );
       
        examPanel = new ExamPanel(this, coursePanel, accessCon);
        studentCourseProfessorExamPanel.add( examPanel );      
       
        c.add( studentCourseProfessorExamPanel, BorderLayout.CENTER ) ;
        controlPanel = new ControlPanel(coursePanel, examPanel,
                                                professorPanel, studentPanel);
        c.add( controlPanel, BorderLayout.NORTH );
        c.add( output, BorderLayout.SOUTH );
       
        pack();
        show();

}
0
 

Author Comment

by:komlaaa
ID: 13640744

Good point from pkwan,
although that did not solve my entire problem that was the solution that solve the StackOverFlowError problem.
I appreciate that. Thanks
0
 

Author Comment

by:komlaaa
ID: 13640749


CAN THE ADMINISTRATOR OF THIS PAGE DELETE THIS QUESTION. TOO LONG
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question