2013-01-13 60 views
1

我新的Java和我試圖做出的Minecraft國防部,但我想不通我怎麼能解決這個錯誤,沒有合適的構造函數:錯誤:發現

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 

這是我的代碼:

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()})); 
     } 
    } 
} 

這是什麼問題我試圖使它的字符串「用戶名」重定向到另一個類。

回答

1

Java編譯器會提醒您不能構建一個Packet2ClientProtocol對象,因爲你的構造函數調用不符合任何已知的構造。

具體來說,編譯器發現兩個構造函數:

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

,但您的來電:

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

匹配沒有。

+0

謝謝!這解決了這個問題。 – Irrationality

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

該錯誤表明這樣的構造函數不存在。

只有2個選項

Packet2ClientProtocol.Packet2ClientProtocol(int,String,int) 
Packet2ClientProtocol.Packet2ClientProtocol() 
+0

我試圖添加一個虛擬構造函數,但我不斷收到語法錯誤,儘管我確信沒有。 – Irrationality

+0

@ user1973458一個虛擬構造函數不會幫助。你顯然打算讓代碼去做一些事情。 –

+0

@ user1973458你可能錯過了一個''''或者一個爭論? –