Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2763

derived class can not inherit its parent method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Won't Fix
    • 1.5.5
    • 1.5.6
    • None
    • None
    • jdk1.6u6

    Description

      The following code can not be executed in Groovy Console, which complains:

      Exception thrown: java.lang.NullPointerException: Cannot invoke method add() on null object
      
      java.lang.NullPointerException: Cannot invoke method add() on null object
      	at Demo.<init>(Script7:82)
      
      import java.awt.BorderLayout;
      import java.awt.Container;
      import java.awt.Dimension;
      import java.awt.Toolkit;
      
      import javax.swing.ImageIcon;
      import javax.swing.JButton;
      import javax.swing.JCheckBox;
      import javax.swing.JComboBox;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JPanel;
      import javax.swing.JPasswordField;
      import javax.swing.JTextField;
      
      public class Demo extends JFrame{
      
          Container contentPane;
          ImageIcon img = new ImageIcon("002.jpg");
         
          JPanel paneTop = new JPanel();
          JPanel paneMid = new JPanel();
          JPanel paneBut = new JPanel();
          JPanel paneAll = new JPanel();
         
          JLabel lblTop = new JLabel();
          JLabel lblName = new JLabel();
          JLabel lblPwd = new JLabel();
          JLabel lblApply = new JLabel();
          JLabel lblForget = new JLabel();
          JLabel lblModel = new JLabel();
          JLabel lblNull = new JLabel();
         
          JTextField txtName = new JTextField(15);
          JPasswordField txtPwd = new JPasswordField(15);
         
          JComboBox cmb = new JComboBox();
         
          JCheckBox chk = new JCheckBox();
         
          JButton btnKill = new JButton("&#26597;&#26432;&#26408;&#39532;");
          JButton btnSet = new JButton("&#35774;&#32622;");
          JButton btnLogin = new JButton("&#30331;&#24405;");
         
         
         
          public Demo(){
              lblTop.setIcon(img);
              paneTop.add(lblTop);
             
              lblName.setText("QQ&#24080;&#21495;:");
              lblApply.setText("&#30003;&#35831;&#24080;&#21495;   ");
              lblPwd.setText("QQ&#23494;&#30721;:");
              lblForget.setText("&#24536;&#35760;&#23494;&#30721;?");
              lblModel.setText("&#29366;&#24577;:");
             
              String[] s1 = ["&#38544;&#36523;","&#22312;&#32447;","&#24537;&#30860;"] as String[];
              cmb.addItem(s1[0]);
              cmb.addItem(s1[1]);
              cmb.addItem(s1[2]);
             
              chk.setText("&#33258;&#21160;&#30331;&#24405;");
             
              paneMid.add(lblName);
              paneMid.add(txtName);
              paneMid.add(lblApply);
             
              paneMid.add(lblPwd);
              paneMid.add(txtPwd);
              paneMid.add(lblForget);
             
              paneMid.add(lblModel);
              paneMid.add(cmb);
              paneMid.add(chk);
             
              paneBut.add(btnKill);
              paneBut.add(btnSet);
              paneBut.add(btnLogin);
             
             contentPane = this.getContentPane();
             
             contentPane.add(paneTop,BorderLayout.NORTH);
             contentPane.add(paneMid,BorderLayout.CENTER);
             contentPane.add(paneBut,BorderLayout.SOUTH);
             
             
             
              setTitle("&#27426;&#36814;&#20351;&#29992;QQ");
              setSize(330,240);
              Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
              setLocation((screen.width - getSize().width)/2,(screen.height - getSize().height)/2 );
              setVisible(true);
              setResizable(false);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       
          }
         
          public static void main(String[] args){
              Demo d = new Demo();
          }
         
      }
      

      After I commented the codes about contentPane variable, the code can not be executed too, the error message suggest us that the inheritance in Groovy does not work:

      Exception thrown: groovy.lang.MissingMethodException: No signature of method: Demo.setLocation() is applicable for argument types: (java.lang.Double, java.lang.Double) values: {475.0, 280.0}
      
      groovy.lang.MissingMethodException: No signature of method: Demo.setLocation() is applicable for argument types: (java.lang.Double, java.lang.Double) values: {475.0, 280.0}
      	at Demo.invokeMethod(Script8)
      	at Demo.<init>(Script8:91)
      
      
      import java.awt.BorderLayout;
      import java.awt.Container;
      import java.awt.Dimension;
      import java.awt.Toolkit;
      
      import javax.swing.ImageIcon;
      import javax.swing.JButton;
      import javax.swing.JCheckBox;
      import javax.swing.JComboBox;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JPanel;
      import javax.swing.JPasswordField;
      import javax.swing.JTextField;
      
      public class Demo extends JFrame{
      
          Container contentPane;
          ImageIcon img = new ImageIcon("002.jpg");
         
          JPanel paneTop = new JPanel();
          JPanel paneMid = new JPanel();
          JPanel paneBut = new JPanel();
          JPanel paneAll = new JPanel();
         
          JLabel lblTop = new JLabel();
          JLabel lblName = new JLabel();
          JLabel lblPwd = new JLabel();
          JLabel lblApply = new JLabel();
          JLabel lblForget = new JLabel();
          JLabel lblModel = new JLabel();
          JLabel lblNull = new JLabel();
         
          JTextField txtName = new JTextField(15);
          JPasswordField txtPwd = new JPasswordField(15);
         
          JComboBox cmb = new JComboBox();
         
          JCheckBox chk = new JCheckBox();
         
          JButton btnKill = new JButton("&#26597;&#26432;&#26408;&#39532;");
          JButton btnSet = new JButton("&#35774;&#32622;");
          JButton btnLogin = new JButton("&#30331;&#24405;");
         
         
         
          public Demo(){
              lblTop.setIcon(img);
              paneTop.add(lblTop);
             
              lblName.setText("QQ&#24080;&#21495;:");
              lblApply.setText("&#30003;&#35831;&#24080;&#21495;   ");
              lblPwd.setText("QQ&#23494;&#30721;:");
              lblForget.setText("&#24536;&#35760;&#23494;&#30721;?");
              lblModel.setText("&#29366;&#24577;:");
             
              String[] s1 = ["&#38544;&#36523;","&#22312;&#32447;","&#24537;&#30860;"] as String[];
              cmb.addItem(s1[0]);
              cmb.addItem(s1[1]);
              cmb.addItem(s1[2]);
             
              chk.setText("&#33258;&#21160;&#30331;&#24405;");
             
              paneMid.add(lblName);
              paneMid.add(txtName);
              paneMid.add(lblApply);
             
              paneMid.add(lblPwd);
              paneMid.add(txtPwd);
              paneMid.add(lblForget);
             
              paneMid.add(lblModel);
              paneMid.add(cmb);
              paneMid.add(chk);
             
              paneBut.add(btnKill);
              paneBut.add(btnSet);
              paneBut.add(btnLogin);
             
            // contentPane = this.getContentPane();
             
             //contentPane.add(paneTop,BorderLayout.NORTH);
            // contentPane.add(paneMid,BorderLayout.CENTER);
            // contentPane.add(paneBut,BorderLayout.SOUTH);
             
             
             
              setTitle("&#27426;&#36814;&#20351;&#29992;QQ");
              setSize(330,240);
              Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
              setLocation((screen.width - getSize().width)/2,(screen.height - getSize().height)/2 );
              setVisible(true);
              setResizable(false);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       
          }
         
          public static void main(String[] args){
              Demo d = new Demo();
          }
         
      }
      

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            daniel_sun Daniel Sun
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: