Yo tous le monde , j'ouvre ce topic car j'ai une erreur qui survient au niveau de mon jeu .
Bref je vous met l'erreur :
Fri May 19 19:32:20 CEST 2017 INFO:Slick Build #237
Fri May 19 19:32:20 CEST 2017 INFO:LWJGL Version: 2.9.2
Fri May 19 19:32:20 CEST 2017 INFO:OriginalDisplayMode: 1920 x 1080 x 32 @60Hz
Fri May 19 19:32:20 CEST 2017 INFO:TargetDisplayMode: 1920 x 1080 x 0 @0Hz
Fri May 19 19:32:21 CEST 2017 INFO:Starting display 1920x1080
Fri May 19 19:32:21 CEST 2017 INFO:Use Java PNG Loader = true
WARNING: Found unknown Windows version: Windows 10
Attempting to use default windows plug-in.
Loading: net.java.games.input.DirectAndRawInputEnvironmentPlugin
Fri May 19 19:32:22 CEST 2017 INFO:Found 2 controllers
Fri May 19 19:32:22 CEST 2017 INFO:0 : Rival Gaming Mouse
Fri May 19 19:32:22 CEST 2017 INFO:1 : SteelSeries Rival
Demande de connexion
Fri May 19 19:32:46 CEST 2017 ERROR:null
java.lang.NullPointerException
at Reseau.Client.demandeco(Client.java:27)
at lesson1.c1.update(c1.java:124)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:663)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at lesson1.c1.main(c1.java:63)
Fri May 19 19:32:46 CEST 2017 ERROR:Game.update() failure - check the game code.
org.newdawn.slick.SlickException: Game.update() failure - check the game code.
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:669)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at lesson1.c1.main(c1.java:63)
alors j'utilise slick2d pour mon jeu , et donc a ce que je voit il s'agit d'une NullPointerExeption ...
Pourtant , j'ai utilisé tous le temps le même code au niveau réseau et ça marchait donc je ne vois pas le problème ...
Si vous voulez le code je le mettrai , je ne le met pas tous de suite au cas ou il n'y a pas besoin , et le code est assez long , je pense que vous n'allez pas passez trop de temps sur ce sujet ...
Voila voila
L'erreur dit clairement qu'il y a un problème à la ligne 27 de ta classe Client.
Erreur ligne 27, j'imagine que y'a une ioexception ligne 16, du coup le socket est null.
Reste à savoir ce qu'il se passe ligne 16
+ Pastbin / Gits / balises code la prochaine fois stp
Pourtant j'ai essayé avec mon adresse locale , j'ai ouvert les ports avec mon adresse ip et tout, j'ai testé avec localhost ...
Pourtant ma derniere version du jeu le serveur / client marchait bien ...
Remplace ta ligne 27 par e.printStackTrace(), on aura sûrement plus d'informations.
même code d'erreur avec e.printstackTrace();
C'est impossible qu'il y ait la même erreur car plus rien ne peut être nul à la ligne 27.
voit par toi même :
Sat May 20 13:44:40 CEST 2017 INFO:Slick Build #237
Sat May 20 13:44:40 CEST 2017 INFO:LWJGL Version: 2.9.2
Sat May 20 13:44:40 CEST 2017 INFO:OriginalDisplayMode: 1366 x 768 x 32 @60Hz
Sat May 20 13:44:40 CEST 2017 INFO:TargetDisplayMode: 1366 x 768 x 0 @0Hz
Sat May 20 13:44:41 CEST 2017 INFO:Starting display 1366x768
Sat May 20 13:44:41 CEST 2017 INFO:Use Java PNG Loader = true
WARNING: Found unknown Windows version: Windows 10
Attempting to use default windows plug-in.
Loading: net.java.games.input.DirectAndRawInputEnvironmentPlugin
Sat May 20 13:44:42 CEST 2017 INFO:Found 2 controllers
Sat May 20 13:44:42 CEST 2017 INFO:0 : Rival Gaming Mouse
Sat May 20 13:44:42 CEST 2017 INFO:1 : SteelSeries Rival
Demande de connexion
Sat May 20 13:45:06 CEST 2017 ERROR:null
java.lang.NullPointerException
at Reseau.Client.demandeco(Client.java:27)
at lesson1.c1.update(c1.java:124)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:663)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at lesson1.c1.main(c1.java:63)
Sat May 20 13:45:06 CEST 2017 ERROR:Game.update() failure - check the game code.
org.newdawn.slick.SlickException: Game.update() failure - check the game code.
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:669)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at lesson1.c1.main(c1.java:63)package Reseau;
import java.io.*;
import java.net.*;
public class Client {
public static Socket socket = null;
public static Thread t1;
public void demandeco() {
try {
System.out.println("Demande de connexion");
socket = new Socket("localhost",2009);
System.out.println("Connexion établie avec le serveur, authentification :");
t1 = new Thread(new Connexion(socket));
t1.start();
} catch (UnknownHostException e) {
System.err.println("Impossible de se connecter à l'adresse "+socket.getLocalAddress());
} catch (IOException e) {
e.printStackTrace();
}
}
}
petit up
Tu n'as pas un client ou un serveur en trop qui tourne ? Au pire redemarre ton PC pour repartir clean.
Des attributs public dans une classe
bon les mecs j'ai resolu le problème ,et je suis vraiment con
Le problème était :
le projet ne pouvait pas charger les librairies car j'avais changé l'emplacement de celle-ci , du coup aucune librairie au chemin indiqué générant ainsi une exception .
le problème est maintenant resolu !
je garde ce topic pour d'autre problème ...
du coup j'ai toujours eu un problème sur ce projet , c'est qu'a chaque deconnection , le serveur tourne en boucle l'erreur connection reset .
Y'aurai t'il quelque chose à faire ?
j'ai lu quelque part qu'il faudrait refermer les sockets a chaque deconnection .
Je suis pas sur de ce que je dit ...
quelqu'un saurait comment faire ça ?
bon je m'en suis sorti tous seul ...
mais maintenant que j'ai avancé j'ai un message d'erreur :
Exception in thread "Thread-9" java.lang.NumberFormatException: For input string: "l"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at Reseau.Reception.run(Reception.java:90)
at java.lang.Thread.run(Unknown Source)
j'ai regardé a la ligne 90 de la classe Reception , et je ne vois rien d'anormal .
Peut être qu'avec la source de la classe en question on peut t'aider...
package Reseau;
import java.io.BufferedReader;
import java.io.IOException;
public class Reception implements Runnable {
private BufferedReader in;
private static String message = null;
private static String snc;
public static int xpa1;
static String nc;
public static int nbct;
public static String iu1x;
public static String iu1y;
public static String iu2x;
public static String iu2y;
public static String iu3x;
public static String iu3y;
public static String iu4x;
public static String iu4y;
public static String iu5x;
public static String iu5y;
public static String iu6x;
public static String iu6y;
public static String iu7x;
public static String iu7y;
public static String iu8x;
public static String iu8y;
public static String iu9x;
public static String iu9y;
public static String iu10x;
public static String iu10y;
public Reception(BufferedReader in){
this.in = in;
}
public void run() {
try {
snc = in.readLine();
nc = snc;
switch(nc){
case "1" :
nc = "01";
break;
case "2" :
nc = "02";
break;
case "3" :
nc = "03";
break;
case "4" :
nc = "04";
break;
case "5" :
nc = "05";
break;
case "6" :
nc = "06";
break;
case "7" :
nc = "07";
break;
case "8" :
nc = "08";
break;
case "9" :
nc = "09";
break;
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
while(true){
try {
message = in.readLine();
//erreur ici iu1x = message.substring(3 , 3 + Integer.parseInt(message.substring(2 , 3)));
nbct = 4+iu1x.length() ;
iu1y = message.substring(nbct , nbct + Integer.parseInt(message.substring( nbct , nbct + 1 )));
nbct = 7 + iu1x.length() + iu1y.length();
/*iu2x = message.substring(nbct , nbct + Integer.parseInt(message.substring( nbct , nbct + 1 )));
nbct += 10 + iu2x.length();
iu2y = message.substring(nbct , nbct + Integer.parseInt(message.substring( nbct , nbct + 1 )));
nbct += 13 + iu2y.length();*/
//System.out.println(iu1x);
/*lesson1.c1.p.setX(Integer.parseInt(iu1x));
lesson1.c1.p.setY(Integer.parseInt(iu1y));
lesson1.c1.pa1.setX(Integer.parseInt(iu2x));
lesson1.c1.pa1.setY(Integer.parseInt(iu2y));*/
} catch (IOException e) {
e.printStackTrace();
}
}
}
Tu essayes de parser des chaînes de caractères qui ne sont pas des nombres avec Integer.parseInt() ce qui lance une NumberFormatException.
Notamment ici l'erreur dit très clairement que tu essaye de transformer la chaîne de caractères "I" en entier ce qui est impossible. Vu le nombre de substring que tu utilises, l'erreur vient probablement de là.
pourtant quand je regarde dans mon code , je ne vois a aucun moment l'implantation d'un caractère "I"
Après ton message = in.readLine();
, affiche le message.