2013-07-29 126 views
-2

好的,我早些時候發佈了this thread,詢問如何在for循環中創建多個值。 經過一段時間我遇到了一個問題,至於我不知道如何解決,也不知道它爲什麼會發生。 這是我的代碼:Java代碼中的未知錯誤

 for(int x = 0; x < con.length; x++) 
    { 
     maxS[x] = main.getConfig().getString("areas." + con[x] + ".max").split(", ").toString(); 
     minS[x] = main.getConfig().getString("areas." + con[x] + ".min").split(", ").toString(); 
     event.getPlayer().sendMessage("1"); 
     for(int y = 0; y < maxS.length; y++) 
     { 
      maxV[y] = new Vector(Integer.parseInt(maxS[y]), Integer.parseInt(maxS[y+1]), Integer.parseInt(maxS[y+2])); 
      minV[y] = new Vector(Integer.parseInt(minS[y]), Integer.parseInt(minS[y+1]), Integer.parseInt(minS[y+2])); 

      event.getPlayer().sendMessage("2"); 
     } 
    } 

錯誤消息:

2013-07-29 20:32:12 [SEVERE] Could not pass event PlayerMoveEvent to FactionPlay v1.6.2 
    org.bukkit.event.EventException 
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427) 
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) 
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477) 
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462) 
at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:227) 
at net.minecraft.server.v1_6_R2.Packet10Flying.handle(SourceFile:136) 
at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296) 
at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:116) 
at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37) 
at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30) 
at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590) 
at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226) 
at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486) 
at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419) 
at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582) 
    Caused by: java.lang.NumberFormatException: For input string: " [Ljava.lang.String;@af7327" 
at java.lang.NumberFormatException.forInputString(Unknown Source) 
at java.lang.Integer.parseInt(Unknown Source) 
at java.lang.Integer.parseInt(Unknown Source) 
at me.BlueJelly.FactionPlay_SP.PlayerListener.onPlayerMove(PlayerListener.java:191) 
at sun.reflect.GeneratedMethodAccessor89.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425) 
... 14 more 

感謝您的幫助。

+5

什麼是你遇到了什麼問題? – Floris

+1

你能告訴我們錯誤嗎? – Bojan

+2

沒有錯誤信息,我們都不能幫你。 – bas

回答

2

從你的錯誤信息判斷,你看起來好像你對Integer.parseInt的調用實際上並沒有得到一個可以解析爲int的字符串。

相反,他們得到字符串" [Ljava.lang.String;@af7327"

你應該重新評估你是如何得到這些字符串


以下行看起來是錯誤的。

maxS[x] = main.getConfig().getString("areas." + con[x] + ".max").split(", ").toString(); 

這可能只是我的C#的經驗談,但我常想到一個.split()調用返回的string的陣列,而不是單一string

這很難說,不看你的代碼的其餘部分,但我希望看到一條線,看起來更像以下

maxS = main.getConfig().getString("areas." + con[x] + ".max").split(", ");