IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

erruor compliation "Jeu Tetris en java"


Sujet :

Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Chef du projet web
    Inscrit en
    Août 2014
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Chef du projet web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Août 2014
    Messages : 18
    Par défaut erruor compliation "Jeu Tetris en java"
    Bonjour à tous,
    Je suis entrain de créer un jeu Tetris sur JAVA en suivant un tutoriel, après avoir taper le coder en essayant de comprendre cout que cout les différents bouts de codes, j'arrive à la phase de la compilation : Eclipse m'affiche une erreur :

    le code source du jeu :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
     
    package com.sumit.plajava;
     
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Point;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.util.ArrayList;
    import java.util.Collections;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
     
    public class TetrisGame extends JPanel{
     
    	private final Point[][][] myPoint = {
    			{
    				//I
    				{new Point(0,1), new Point(1,1), new Point(2,1), new Point(3,1)},
    				{new Point(1,0), new Point(1,1), new Point(1,2), new Point(1,3)},
    				{new Point(0,1), new Point(1,1), new Point(2,1), new Point(3,1)},
    				{new Point(1,0), new Point(1,1), new Point(1,2), new Point(1,3)}
     
     
    			},
    			{
    				//J
    				{new Point(0,1), new Point(1,1), new Point(2,1), new Point(2,0)},
    				{new Point(1,0), new Point(1,1), new Point(1,2), new Point(2,2)},
    				{new Point(0,1), new Point(1,1), new Point(2,1), new Point(0,2)},
    				{new Point(1,0), new Point(1,1), new Point(1,2), new Point(1,3)}
     
     
    			},
    			{
    				//L 
    				{new Point(0,1), new Point(1,1), new Point(2,1), new Point(2,0)},
    				{new Point(1,0), new Point(1,1), new Point(1,2), new Point(2,2)},
    				{new Point(0,1), new Point(1,1), new Point(2,1), new Point(0,2)},
    				{new Point(1,0), new Point(1,1), new Point(1,2), new Point(2,0)}
     
     
    			},
    			{
    				//0
    				{new Point(0,0), new Point(0,1), new Point(01,0), new Point(1,1)},
    				{new Point(0,0), new Point(0,1), new Point(01,0), new Point(1,1)},
    				{new Point(0,0), new Point(0,1), new Point(01,0), new Point(1,1)},
    				{new Point(0,0), new Point(0,1), new Point(01,0), new Point(1,1)}
     
     
    			},
     
    	};
     
    private final Color[] myColor = {Color.CYAN, Color.magenta, Color.orange, Color.YELLOW, Color.black, Color.PINK, Color.red};
    private Point pt;
    private int currentPiece;
    private int rotation;
    private ArrayList<Integer> nextPiece = new ArrayList<Integer>();
    private long score;
    private Color[][] well;
     
    private void init() {
    	well = new Color[12][24];
    	for(int i = 0; i < 12; i++) {
    		for(int j = 0; j < 23; j++) {
    			if(i == 0 || i == 11 || i == 22) {
    				well[i][j] = Color.PINK;
     
    			}else {
    				well[i][j] = Color.black;
    			}
    		}
     
    	}
    	newPiece();
    }
     
    public void newPiece() {
    	pt = new Point(5,2);
    	rotation = 0;
    	if(nextPiece.isEmpty()) {
    		Collections.addAll(nextPiece, 0,1,2,3);
    		Collections.shuffle(nextPiece);
    	}
     
    }
     
    private boolean collidesAt(int x, int y, int rotation) {
    	for(Point p: myPoint[currentPiece][rotation]) {
    		if(well[p.x+x][p.y+y] != Color.black) {
    			return true;
    		}
    	}
    	return false;
    }
     
    	private void rotate(int i) {
     
    		int newRotation=(rotation + i)%4;
    		if(newRotation < 0) {
    			newRotation = 3;
    		}
     
    		if(!collidesAt(pt.x, pt.y, newRotation)) {
    			rotation = newRotation;
    		}
    		repaint();
    	}
     
    	public void move(int i) {
    		if(!collidesAt(pt.x, pt.y, rotation)) {
    			pt.x += i; 
    		}
    		repaint();
    	}
     
    	public void drop() {
    		if(!collidesAt(pt.x, pt.y, rotation)) {
    			pt.x += 1; 
    		}else {
    			fixtoWell();
    		}
    		repaint();
    	}
     
    	public void fixtoWell() {
    		for(Point p: myPoint[currentPiece][rotation]) {
    			well[pt.x + p.x][pt.y + p.y] = myColor[currentPiece];
    		}
    		clearRows();
    		newPiece();
    	}
     
    	public void deleteRow(int row) {
     
    		for(int j = row - 1; j > 0; j--) {
    			for(int i = 1; i < 11; i++) {
    				well[i][j + 1] = well [i][j];
    			}
    		}
    	}
     
    	public void clearRows() {
    		boolean gap;
    		int numClear = 0;
    		for(int j = 21; j > 0; j--) {
    			gap = false;
    			for(int i = 1; i < 11; i++) {
    				if(well[i][j] == Color.black) {
    					gap = true;
    					break;
     
    				}
    			}
    			if(!gap) {
    				deleteRow(numClear);
     
    					j+=1;
    					numClear+=1;
    			}
    			}
     
    		switch(numClear) {
    		case 1 :
    			score+=100;
    			break;
    		case 2 :
    			score+=300;
    			break;
    		case 3 :
    			score+=500;
    			break;
    		case 4 :
    			score+=800;
    			break;
    		}
     
     
    	}
     
    	private void drawPiece(Graphics g) {
     
    		g.setColor(myColor[currentPiece]);
    		for(Point p: myPoint[currentPiece][rotation]) {
    			g.fillRect((p.x + pt.x) *26, (pt.y + p.y) * 26, 25, 25);
    		}
    	}
     
    	public void paintComponent(Graphics g) {
    		g.fillRect(0, 0, 26 * 12, 26 * 23);
    		for(int i = 0; i < 23; i++) {
    			for(int j = 0; j < 23; j++) {
    				g.setColor(well[i][j]);
    				g.fillRect(26*i, 26*j, 25, 25);
    			}
    			} 
    		g.setColor(Color.WHITE);
    		g.drawString("Score is :"+score, 19*12, 25);
    		drawPiece(g);
     
    		}
     
     
    //main
    	public static void main(String[] args) {
     
     
    		JFrame f = new JFrame("MyGame");
    		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		f.setSize(12*26+10, 26*23+25);
    		f.setVisible(true);
     
    		final TetrisGame game = new TetrisGame();
    		game.init();
    		f.add(game);
     
    		f.addKeyListener(new KeyListener() {
     
    			@Override
    			public void keyTyped(KeyEvent e) {
    				// TODO Auto-generated method stub
     
    			}
     
    			@Override
    			public void keyReleased(KeyEvent e) {
    				// TODO Auto-generated method stub
     
    			}
     
    			@Override
    			public void keyPressed(KeyEvent e) {
     
    				switch(e.getKeyCode()) {
    				case KeyEvent.VK_UP:
    					game.rotate(-1);
    					break;
     
    				case KeyEvent.VK_DOWN:
    					game.rotate(+1);
    					break;
     
    				case KeyEvent.VK_LEFT:
    					game.move(-1);
    					break;
     
    				case KeyEvent.VK_SPACE:
    					game.drop();
    					game.score+=1;
    					break;
     
    				}
     
    			}
    		});
     
    		new Thread() {
    			public void run() {
    				while(true) {
    					try {
    						Thread.sleep(1000);
    					} catch (InterruptedException e) {
    						// TODO Auto-generated catch block
    						e.printStackTrace();
    					}
    					game.drop();
    				}
    			}
    		}.start();
     
     
    	}
     
    }
    Voilà l'erreur que la console m'affiche :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Error: Could not find or load main class com.sumit.plajava.TetrisGame
    Caused by: java.lang.ClassNotFoundException: com.sumit.plajava.TetrisGame
    J'ai essayé de compiler en utilisant la console j'ai qu'un fenêtre grise qui s'affiche sans rien d'autre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    javac -d . [FileName.java]
     
    To Run the class please use this command:
     
    java [Package].[ClassName]
    Merci pour votre aide

  2. #2
    Membre actif
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2017
    Messages
    57
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Août 2017
    Messages : 57
    Par défaut
    Salut,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Error: Could not find or load main class com.sumit.plajava.TetrisGame
    Caused by: java.lang.ClassNotFoundException: com.sumit.plajava.TetrisGame
    J'ai pas d'erreur chez moi,
    Tu l'a nommé comment ta classe ? Tu sais dans ton arborescence. C'est bien le même nom que celui que t'as mis dans ton code ?

  3. #3
    Membre averti
    Homme Profil pro
    Chef du projet web
    Inscrit en
    Août 2014
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Chef du projet web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Août 2014
    Messages : 18
    Par défaut
    Voila comment se présente mon interface Eclipse, il m'invite à redéfinir le PATH avec le plus à gauche de l'import
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    package com.sumit.plajava;
    Nom : eclipse-erreur.jpg
Affichages : 379
Taille : 263,4 Ko

  4. #4
    Membre actif
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2017
    Messages
    57
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Août 2017
    Messages : 57
    Par défaut
    C'est toi qui l'a créé le projet ?

    De plus, l'erreur est différente de toute à l'heure, t'as bien essayé de compiler le bon projet là ?

  5. #5
    Membre averti
    Homme Profil pro
    Chef du projet web
    Inscrit en
    Août 2014
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Chef du projet web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Août 2014
    Messages : 18
    Par défaut
    En fait, avant de poster mon problème, j'ai crée un nouveau projet avec package par défaut, quand j'ai vu qu'avec le "com.sumit.plajava" ça m'affiche des erreurs. Mais, même avec le package par défaut j'ai toujours des erreurs (j'ai l'impression que les erreurs se ressemblent), j'ai donc supprimé le projet avec package par déet je suis resté sur l'ancien (le premier "TetrisGame.java", Projet "Tetris", "class com.sumit.plajava".

    Quand j'execute mon projet j'ai cette erreur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Error: Unable to initialize main class com.sumit.plajava.TetrisGame
    Caused by: java.lang.NoClassDefFoundError: [LString;
    Nom : eclipse-erreur-1.jpg
Affichages : 299
Taille : 244,9 Ko

  6. #6
    Membre actif
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2017
    Messages
    57
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Août 2017
    Messages : 57

Discussions similaires

  1. [Débutant] Programmer le jeu Sudoku en Java
    Par whally dans le forum Graphisme
    Réponses: 5
    Dernier message: 04/03/2011, 09h53
  2. jeu à developper en java
    Par edhecasa dans le forum Général Java
    Réponses: 1
    Dernier message: 15/02/2009, 17h20
  3. [Conseil]Projet de jeu en binôme JAVA
    Par Vivian Pennel dans le forum Développement 2D, 3D et Jeux
    Réponses: 7
    Dernier message: 30/07/2008, 17h21
  4. Petit tetris en java
    Par freeedom dans le forum Développement 2D, 3D et Jeux
    Réponses: 3
    Dernier message: 23/05/2008, 16h42
  5. [Débutant] Developper un jeu DirectX en Java
    Par akito dans le forum DirectX
    Réponses: 5
    Dernier message: 10/08/2007, 07h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo