实际参数列表和形式参数列表长度不同

J2EE 码拜 9年前 (2015-11-12) 3907次浏览
class ButtonDemo2 extends JFrame//输出结果窗口
 {
      public static final int WIDTH=1000;
      public static final int HEIGHT=680;
  public String rlt=””;
  JFrame overGUI;
  ButtonDemo2(String jg2)
   {
    overGUI=new JFrame(“测试系统”);
overGUI.setSize(WIDTH,HEIGHT); 
    overGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Toolkit kit=Toolkit.getDefaultToolkit();
    Dimension screenSize=kit.getScreenSize();
    int width=screenSize.width;
    int height=screenSize.height;
    int x=(width-WIDTH)/2;
    int y=(height-HEIGHT)/2;
    overGUI.setLocation(x,y);
    Panel p=new Panel();
    Container conPane=getContentPane();
    overGUI.add(conPane);
    conPane.setBackground(Color.WHITE);
    conPane.setLayout(new FlowLayout());//采用FlowLayout布局 
    this.setLayout(null);
    JLabel jl=new JLabel(“测试结果如下:”); 
    JTextArea j2=new JTextArea (12,30);
    JButton retheck=new JButton(“再测”);
    JButton repint=new JButton(“打印结果”);
JButton redBut=new JButton(“关闭”);
    conPane.add(jl);
    conPane.add(j2);
    conPane.add(retheck);
conPane.add(repint);
conPane.add(redBut);//在窗口添加Red按钮
    j2.setVisible(true);
j2.setBounds(158,160,730,320);
    j2.setFont(new Font(“宋体”, Font.BOLD, 16));
   GregorianCalendar gc1=new GregorianCalendar();
    String s8=”**************************************************\n”;
String ss=”祝福您!\n”;
    String ssn=gc1.get(Calendar.YEAR)+”年”+(gc1.get(Calendar.MONTH)+1)+”月”+gc1.get(Calendar.DATE)+”日”+
          gc1.get(Calendar.HOUR_OF_DAY)+”时”+gc1.get(Calendar.MINUTE)+”分”;
    j2.setText(ButtonDemo.jg+jg2+s8+ss+ssn); //传递参数jg2,与添加字符串连接,并在文本域中输出
    jl.setBounds(360,20,300,36);//这是控制标签位置;
    jl.setFont(new Font(“宋体”, Font.BOLD, 28));//控制文本字体,那个20就是大小选择,可以改变的  
    retheck.setBounds(380,520,80,30);
repint.setBounds(500,520,100,30);
redBut.setBounds(640,520,80,30);
overGUI.setVisible(true);
    overGUI.setResizable(false);
rlt=j2.getText().toString();
    Test input=new Test(rlt);
    retheck.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e)//实现接口处理事件的方法
 {   
         
    Boolean bp0=e.getActionCommand().equals(“再测”);
    if(bp0)//是“下一步”按钮事件
        {
overGUI.dispose();
ButtonDemo beginGUI1=new ButtonDemo(); 
        }
    
    else{}   
      }
    });      
    
    redBut.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e)//实现接口处理事件的方法
 {   
         
    Boolean bp=e.getActionCommand().equals(“关闭”);
    if(bp)//是“下一步”按钮事件
        {overGUI.dispose();
         
        }
    
    else{}   
      }
    });
  }
}
    class Test {
  public void Test(String dt) throws IOException {
File file = new File(“d:\1.txt”);
FileOutputStream fos=new FileOutputStream(file);
        OutputStreamWriter dw=new OutputStreamWriter(fos);
dw.write(dt);
dw.flush();
dw.close();
}
}
— javac(编译) —
java:1108: 错误: 无法将类 Test中的构造器 Test应用到给定类型;
    Test input=new Test(rlt);
               ^
  需要: 没有参数
  找到: String
  原因: 实际参数列表和形式参数列表长度不同
解决方案:60分
这个“public void Test(String dt) throws IOException”只是Test类中的一个方法,不是构造函数。
正确的调用语法是:
Test input=new Test();
input.Test(rlt);
或直接new Test().Test(rlt);

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明实际参数列表和形式参数列表长度不同
喜欢 (0)
[1034331897@qq.com]
分享 (0)