Results 1 to 6 of 6
  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,037
    Rep Power
    8

    Default error says "can not find method.....

    1) when I have an inner clase called:

    Java Code:
     public class SingleRoomInfo  { // principle class holds all room info
           
           private JLabel panelref,firstname, lastname, pianoicon, 
                   roomfree, reserved ,endtime;
           
    
           public void setFirstName(JLabel fn)  {
               firstname = fn;
           } // more methods etc.
    }
    2) and I declare the next field in the main clase:
    private SingleRoomPanel[] singleroompanel;

    3) and Initialize the above like this:

    Java Code:
     singleroompanel = new SingleRoomPanel[MAXROOM]; // initialize the 
            for (int i = 0; i < singleroompanel.length; i++) { // roominfopanrl array
              singleroompanel[i] = new SingleRoomPanel();
            }
    4) why I get an error when saying in a other method
    singleroompanel[panelcount].setFirstName(new JLabel("firstname"));

    (error says "can not find method setFirstName")

    why can't programming be easier......

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,931
    Rep Power
    4

    Default Re: error says "can not find method.....

    Please show the offending code in the context in which the error occurred.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,037
    Rep Power
    8

    Default Re: error says "can not find method.....

    It is a little messy, still working on it

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package roomassigment;
    
    import java.awt.Dimension;
    import javax.swing.*;
    
    
    /**
     *
     *  */
    public class SingleRoomPanel extends JPanel {
        private Box bh1, bh2, bh3, bv1, bv2;
        private JLabel firstname, lastname, endtime, reserved;
        private JProgressBar TimeBar;
        private SingleRoomPanel[] singleroompanel;
        private final static int MAXROOM = 90;
        private int panelcount;
    
    
        public static void main(String[] args) {
    
        }
    
        public SingleRoomPanel()   {
            
            panelcount = 0;
            
            singleroompanel = new SingleRoomPanel[MAXROOM]; // initialize the 
            for (int i = 0; i < singleroompanel.length; i++) { // roominfopanrl array
              singleroompanel[i] = new SingleRoomPanel();
            }
            
        }
        
       
        public JPanel CreateSingleRoomPanel(JPanel jp)   {
    
            jp.setLayout(new BoxLayout(jp, BoxLayout.LINE_AXIS));
            firstname = new JLabel("firstname");
            singleroompanel[panelcount].setFirstName(new JLabel("firstname")); 
          
            TimeBar = new JProgressBar(0, 60);
            TimeBar.setPreferredSize( new Dimension( 5, 60 ) );
            TimeBar.setStringPainted(false);
            TimeBar.setValue(0);
            TimeBar.setOrientation(SwingConstants.VERTICAL);
            TimeBar.setStringPainted(true);
    
            bh1 = Box.createHorizontalBox();
            bh2 = Box.createHorizontalBox();
            bh3 = Box.createHorizontalBox();
            bv1 = Box.createVerticalBox();
            bv2 = Box.createVerticalBox();
    
            jp.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
            bh1.add(firstname);
            bh1.add(Box.createGlue());
            bh1.add(TimeBar);
    
            bh2.add(lastname);
            bh2.add(Box.createGlue());
    
            bh3.add(Box.createHorizontalStrut(25));
            bh3.add(reserved);
            bh3.add(Box.createGlue());
            bh3.add(endtime);
    
            bv1.add(bh1);
            bv1.add(bh2);
            bv1.add(Box.createVerticalStrut(5));
            bv1.add(bh3);
            bv1.add(Box.createVerticalStrut(2));
    
            jp.add(bv1);
            panelcount++;
            return jp;
        }
    
        public void setRoompanel(int panelindex, String fn, String ln,
                String et, Boolean res) {
    
        }
    
         
         public class SingleRoomInfo  { // principle class holds all room info
           
           private JLabel panelref,firstname, lastname, pianoicon, 
                   roomfree, reserved ,endtime;
           
    
           public void setFirstName(JLabel fn)  {
               firstname = fn;
           }
           public JLabel getFirstName()  {
               return firstname;
           }
           public void setLastName(JLabel ln)  {
               lastname = ln;
           }
           
           public JLabel getLastName()  {
               return lastname;
           }
    
            public void setPianoIcon(JLabel pf)  {
               pianoicon = pf;
           }
           public JLabel getPianoIcon()  {
               return pianoicon;
           }
    
           public void setEndTime(JLabel et)  {
               endtime = et;
           }
           public JLabel getEndTime()  {
               return endtime;
           }
           public void setReserved(JLabel rs)  {
               reserved = rs;
           }
           public JLabel getReserved()  {
               return reserved;
           }
    
         }
     
    }

  4. #4
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,037
    Rep Power
    8

    Default Re: error says "can not find method.....

    line 44 is the accused one

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,931
    Rep Power
    4

    Default Re: error says "can not find method.....

    Because the method is in SingleRoomInfo not SingleRoomPanel.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #6
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,037
    Rep Power
    8

    Default Re: error says "can not find method.....

    Jim, right, how silly of me, sorry!

Similar Threads

  1. How Does Java Find the "main" Method?
    By bobg in forum New To Java
    Replies: 3
    Last Post: 05-16-2011, 04:09 AM
  2. Receiving error "Could not find the main class"
    By Kalpesh in forum New To Java
    Replies: 2
    Last Post: 02-02-2011, 06:31 PM
  3. Error message "could not find the main class"
    By srwpchelp in forum New To Java
    Replies: 8
    Last Post: 12-23-2010, 09:15 PM
  4. Replies: 1
    Last Post: 06-30-2009, 02:32 PM
  5. "Cannont find symbol Constructor" error
    By Welsh in forum New To Java
    Replies: 7
    Last Post: 01-25-2008, 12:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •