Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

[java] Java class don't get compiled

Started by programering Oct 18, 2008 at 9:27 AM 13 replies 1.8k views
Original Post
programering
programering
I'm recreating a java game and one java class (PlayerDef) don't get compiled into the .class file (PlayerDef.class), why? What can cause this? I need that to work as usual. Here is the code: Player.java:



class Player
{

	static final int ACTION_IDLE = 0;
	static final int ACTION_WALK = 1;
	static final int ACTION_JUMP = 2;

	static int NUM_PLAYER_DEFS = 1;

	static PlayerDef defs[];

	static void loadDefs()
	{
		defs = new PlayerDef[NUM_PLAYER_DEFS];

		for (int i = 0; i < NUM_PLAYER_DEFS; i++)
			defs = new PlayerDef(i);
	}

	static int NUM_CONTROLS = 1;

	static Controls ctrls[];

	static void loadControls()
	{
		ctrls = new Controls[NUM_CONTROLS];

		for (int i = 0; i < NUM_CONTROLS; i++)
			ctrls = new Controls(i);
	}


	PlayerDef playDef;
	Controls controls;
	Entity player;


	Player(int idef, int ctrl)
	{
		playDef = defs[idef];
		controls = ctrls[ctrl];
	}

	void bind(Entity ent)
	{
		player = ent;
	}

	void create(int x, int y)
	{
		player = new Entity(Entity.PLAYER,x,y);
	}

	void update()
	{
	}
}




PlayerDef.java:




import java.awt.Image;




class PlayerDef
{
	static final int DOGGY = 0;

	static int DIRECTION_LEFT = 0;
	static int DIRECTION_RIGHT = 1;
	static int NUM_DIRECTIONS = 2;

	static int NUM_FRAMES = 2;

	Image idle[];
	Image move[][];
	Image jump[][];

	Image idleDark[];
	Image moveDark[][];
	Image jumpDark[][];

	PlayerDef(int idef)
	{
		idle = new Image[NUM_DIRECTIONS];
		move = new Image[NUM_DIRECTIONS][NUM_FRAMES];
		jump = new Image[NUM_DIRECTIONS][NUM_FRAMES];

		idleDark = new Image[NUM_DIRECTIONS];
		moveDark = new Image[NUM_DIRECTIONS][NUM_FRAMES];
		jumpDark = new Image[NUM_DIRECTIONS][NUM_FRAMES];

		switch (idef)
		{
			case DOGGY:
				idle[DIRECTION_LEFT] = Media.getImage("dl.gif");
				idle[DIRECTION_RIGHT] = Media.getImage("dr.gif");
				move[DIRECTION_LEFT][0] = Media.getImage("dl1.gif");
				move[DIRECTION_LEFT][1] = Media.getImage("dl2.gif");
				move[DIRECTION_RIGHT][0] = Media.getImage("dr1.gif");
				move[DIRECTION_RIGHT][1] = Media.getImage("dr2.gif");
				jump[DIRECTION_LEFT][0] = Media.getImage("jump_left.gif");
				jump[DIRECTION_LEFT][1] = Media.getImage("jump_left2.gif");
				jump[DIRECTION_RIGHT][0] = Media.getImage("jump_right.gif");
				jump[DIRECTION_RIGHT][1] = Media.getImage("jump_right2.gif");

				idleDark[DIRECTION_LEFT] = Media.getImage("sdog_left1.gif");
				idleDark[DIRECTION_RIGHT] = Media.getImage("sdog_right1.gif");
				moveDark[DIRECTION_LEFT][0] = Media.getImage("sdog_left1.gif");
				moveDark[DIRECTION_LEFT][1] = Media.getImage("sdog_left2.gif");
				moveDark[DIRECTION_RIGHT][0] = Media.getImage("sdog_right1.gif");
				moveDark[DIRECTION_RIGHT][1] = Media.getImage("sdog_right2.gif");
				jumpDark[DIRECTION_LEFT][0] = Media.getImage("sd_jmp_left.gif");
				jumpDark[DIRECTION_LEFT][1] = Media.getImage("sd_jmp2_l1.gif");
				jumpDark[DIRECTION_RIGHT][0] = Media.getImage("sd_jmp_right.gif");
				jumpDark[DIRECTION_RIGHT][1] = Media.getImage("sd_jmp2_r1.gif");
				break;
			default:
				break;
		}
	}
}






Stani R
Stani R
What compiler errors are you getting? My first guess would be that you forgot to include whatever package the Media class is in.
programering
programering
Quote:
Original post by lightbringer
What compiler errors are you getting? My first guess would be that you forgot to include whatever package the Media class is in.

I got no compiler errors it successfully built the .class files without that PlayerDef.class. The Media class is my own, and you do not need to include(import) java source files that are in the same directory. It is in Media.java source file.
leif_dragon
leif_dragon
have you already compiled the PlayerDef.java file separately? If you just compile the class using playerDef as an object it may compile but not actually use the class.
programering
programering
Quote:
Original post by leif_dragon
have you already compiled the PlayerDef.java file separately?

Yes I have done so to get on with it.


Quote:
Original post by leif_dragon
If you just compile the class using playerDef as an object it may compile but not actually use the class.

I don't understand that sentence.
Stani R
Stani R
I'm a bit confused. You first said that you cannot compile PlayerDef.class, but now it seems that you can. Which is it?
programering
programering
Quote:
Original post by lightbringer
I'm a bit confused. You first said that you cannot compile PlayerDef.class, but now it seems that you can. Which is it?

Yes I compiled it manually(typed: "javac PlayerDef.java" in the cmd) to get on with it without finding the fault.
ToohrVyk
ToohrVyk
Quote:
Original post by programering
Yes I compiled it manually [...]

... as opposed to?

programering
programering
Quote:
Original post by ToohrVyk
Quote:
Original post by programering
Yes I compiled it manually [...]

... as opposed to?

... to compile the main application .java file.
CaptainJester
CaptainJester
Quote:
Original post by OrangyTang
Compilation in java is not recursive, you have to specify the file name of every source file you want compiled.

Actually it is.
Quote:

When compiling a source file, the compiler often needs information about a type whose definition did not appear in the source files given on the command line. The compiler needs type information for every class or interface used, extended, or implemented in the source file. This includes classes and interfaces not explicitly mentioned in the source file but which provide information through inheritance.

..

When the compiler needs type information, it looks for a source file or class file which defines the type. The compiler searches for class files first in the bootstrap and extension classes, then in the user class path (which by default is the current directory). The user class path is defined by setting the CLASSPATH environment variable or by using the -classpath command line option.


He was probably having a classpath issue.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
OrangyTang
OrangyTang
Quote:
Original post by CaptainJester
Quote:
Original post by OrangyTang
Compilation in java is not recursive, you have to specify the file name of every source file you want compiled.

Actually it is.
Quote:

When compiling a source file, the compiler often needs information about a type whose definition did not appear in the source files given on the command line. The compiler needs type information for every class or interface used, extended, or implemented in the source file. This includes classes and interfaces not explicitly mentioned in the source file but which provide information through inheritance.

..

When the compiler needs type information, it looks for a source file or class file which defines the type. The compiler searches for class files first in the bootstrap and extension classes, then in the user class path (which by default is the current directory). The user class path is defined by setting the CLASSPATH environment variable or by using the -classpath command line option.


He was probably having a classpath issue.

Well blow me so it is. Shows how long since I manually compiled anything via the command line. [ignore]
programering
programering
The question was why just that PlayerDef.class didn't build.
Stani R
Stani R
Quote:
Original post by programering
The question was why just that PlayerDef.class didn't build.


Like OrangyTang I also haven't compiled from command line for a long, long time, so I'm not sure just from the limited info you've given us. What you can try is deleting those class files and running "javac -verbose Player.java". Maybe it will report the problem.
Haladria
Haladria
I recommend you to switch to Eclipse or similar if you are gonna continue developing in java. It will help you with these kinds of errors and setting up build paths and so..

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.