error: no suitable constructor found for

狂风中的少年 提交于 2019-12-17 20:28:42

问题


I am new to java, and am trying to make a mod for Minecraft, but I can't figure out how I can fix this error:

src\minecraft\net\minecraft\src\ThreadConnectToServer.java:39: error: no suitabl
e constructor found for Packet2ClientProtocol(int,Minecraft,String,String,int)
        GuiConnecting.getNetClientHandler(this.connectingGui).addToSendQueue
(new Packet2ClientProtocol(51, GuiConnecting.func_74254_c(this.connectingGui), t
his.Username, this.ip, this.port));

^

constructor Packet2ClientProtocol.Packet2ClientProtocol(int,String,int) is n
ot applicable
  (actual and formal argument lists differ in length)
constructor Packet2ClientProtocol.Packet2ClientProtocol() is not applicable
  (actual and formal argument lists differ in length)
1 error

This is my code:

package net.minecraft.src;

import java.net.ConnectException;
import java.net.UnknownHostException;

public class ThreadConnectToServer extends Thread
{

/** The IP address or domain used to connect. */
    final String ip;

    /** The port used to connect. */
    final int port;

    /** A reference to the GuiConnecting object. */
    final GuiConnecting connectingGui;

final String Username;

    ThreadConnectToServer(GuiConnecting par1GuiConnecting, String par2Str, int par3)
    {
        this.connectingGui = par1GuiConnecting;
        this.ip = par2Str;
        this.port = par3;
        String Username = Info.Username;
    }

    public void run()
    {
        try
        {
            GuiConnecting.setNetClientHandler(this.connectingGui, new NetClientHandler(GuiConnecting.func_74256_a(this.connectingGui), this.ip, this.port));

            if (GuiConnecting.isCancelled(this.connectingGui))
            {
                return;
            }

            GuiConnecting.getNetClientHandler(this.connectingGui).addToSendQueu(new Packet2ClientProtocol(51, GuiConnecting.func_74254_c(this.connectingGui), this.Username, this.ip, this.port));
            }
            catch (UnknownHostException var2)
            {
                if (GuiConnecting.isCancelled(this.connectingGui))
                {
                    return;
                }

        GuiConnecting.func_74249_e(this.connectingGui).displayGuiScreen(new GuiDisconnected("connect.failed", "disconnect.genericReason", new Object[] {"Unknown host \'" + this.ip + "\'"}));
    }
    catch (ConnectException var3)
    {
        if (GuiConnecting.isCancelled(this.connectingGui))
        {
            return;
        }

        GuiConnecting.func_74250_f(this.connectingGui).displayGuiScreen(new GuiDisconnected("connect.failed", "disconnect.genericReason", new Object[] {var3.getMessage()}));
    }
    catch (Exception var4)
    {
        if (GuiConnecting.isCancelled(this.connectingGui))
        {
            return;
        }

        var4.printStackTrace();
        GuiConnecting.func_74251_g(this.connectingGui).displayGuiScreen(new GuiDisconnected("connect.failed", "disconnect.genericReason", new Object[] {var4.toString()}));
        }
    }
}

What is wrong with this I'm trying to make it so that the string "Username" redirects to another class.


回答1:


The Java compiler is telling you that cannot construct a Packet2ClientProtocol object, because your call to the constructor does not match any known constructor.

Specifically, the compiler found two constructors:

Packet2ClientProtocol.Packet2ClientProtocol(int,String,int)
Packet2ClientProtocol.Packet2ClientProtocol()

but your call to:

new Packet2ClientProtocol(51, GuiConnecting.func_74254_c(this.connectingGui), this.Username, this.ip, this.port)

matches none of them.




回答2:


new Packet2ClientProtocol(51, GuiConnecting.func_74254_c(this.connectingGui), this.Username, this.ip, this.port)

The error indicates that such a constructor does not exist.

There are only 2 options

Packet2ClientProtocol.Packet2ClientProtocol(int,String,int)
Packet2ClientProtocol.Packet2ClientProtocol()


来源:https://stackoverflow.com/questions/14300449/error-no-suitable-constructor-found-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!