我目前正在使用Notepad ++和Java JDK 7處理小型2D遊戲。我不想使用Eclipse之類的IDE,因此我的java文件和類位於我的C:\ Users \ Jeremy \ Documents \ ZombieSurvival目錄。要編譯和運行我的代碼我使用記事本+ +的npexec插件,執行命令:Java ClassDefFoundError&NoClassFoundException
C:\ Program Files文件\的Java \ jdk1.7.0_79 \ BIN \ javac的Game.java(編譯)
C:\ Program Files文件\的Java \ jdk1.7.0_79 \ BIN \ Java遊戲(運行)
一切是工作,直到我開始編寫我的tilemap的類。如果我使用這個類,會彈出一個ClassNotFoundError和NoClassDefFoundException。這很好奇,因爲在另一場我的Java遊戲中,我的Map類中顯示了同樣的錯誤,所以我的TileMap類錯誤的原因是什麼?就像我說的,沒有使用這個類,程序運行完美!有任何想法嗎?
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.*;
public class TileMap {
private int[][] map;
private int mapWidth;
private int mapHeight;
private int tileSize;
private BufferedImage image;
private Graphics2D g;
public TileMap(String file, int tileSize) {
this.tileSize = tileSize;
loadMap(new File(file));
}
public void update() {
}
public void render(Graphics2D g) {
g.drawImage(image, 0, 0, null);
}
private void loadMap(File file) {
BufferedReader reader = new BufferedReader(new FileReader(file));
mapWidth = Integer.parseInt(reader.readLine());
mapHeight = Integer.parseInt(reader.readLine());
map = new int[mapHeight][mapWidth];
image = new BufferedImage(mapWidth, mapHeight, BufferedImage.TYPE_INT_RGB);
g = (Graphics2D) image.getGraphics();
for(int col = 0; col < mapHeight; col ++) {
String line = reader.readLine();
String[] tokens = line.split(" ");
for(int row = 0; row < mapWidth; row++) {
map[col][row] = Integer.parseInt(tokens[row]);
}
}
}
private void drawMap() {
for(int col = 0; col < mapHeight; col ++) {
for(int row = 0; row < mapWidth; row++) {
int block = map[col][row];
if(block == 1) {
g.setColor(Color.BLACK);
} else {
g.setColor(Color.WHITE);
}
g.fillRect(row * tileSize, col * tileSize, tileSize, tileSize);
}
}
}
}
你確定要編譯你的TileMap.java嗎?您需要確保.class文件也位於類路徑中。 –
請爲其他類和輸出顯示javac cmd。 – Zelldon