Any Ideas?

Started by
3 comments, last by Clobslee 8 years, 9 months ago

I don't do this often, but I have no idea why this is happening. I'm self taught so a lot of the time it's something simple that I just haven't realized yet!

I'm assuming it has something to do with the package it's in, and the command I'm using to compile and run. I'm not sure how the class I just compiled can be missing when I go to run?

Here is the error...


colby@monkeybuckets ~/attempt/core/src/com/evergeen/attempt $ sudo javac -cp ".:kryonet-2.21-all.jar" GameServer.java PosPack.java ServerPlayer.java 
colby@monkeybuckets ~/attempt/core/src/com/evergeen/attempt $ sudo java -cp ".:kryonet-2.21-all.jar" GameServer
Exception in thread "main" java.lang.NoClassDefFoundError: GameServer (wrong name: com/evergeen/attempt/GameServer)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

Here is the class.


package com.evergeen.attempt;

import java.util.*;
import com.esotericsoftware.kryonet.*;
import com.esotericsoftware.kryo.Kryo;


public class GameServer
{
	Server server;
	Kryo kryo;
	LinkedList<ServerPlayer> players;
	
	public static void main(String [] args)
	{
		GameServer gameServer = new GameServer();
		gameServer.runServer();					
	}

	public GameServer()
	{
		System.out.println("Instance Created...");
	}

	public ServerPlayer playerWithId(int id)
	{
		for (ServerPlayer player: players)
			if(player.id == id)
				return player;

		System.out.println("No player with that ID");
		return null;
	}

	public boolean runServer()
	{
		server = new Server();
   		server.start();
		players = new LinkedList<ServerPlayer>();

		try
		{
    		 	server.bind(54555, 54777);
			System.out.println("Server Running...");
		}
		catch (Exception e)
		{
			System.out.println("Couldn't bind to port tard ass");
			System.exit(0);
		}

		kryo = server.getKryo();
		kryo.register(PosPack.class);

		server.addListener(new Listener()
		{
				public void received(Connection connection, Object object)
				{
					System.out.println("Recieved packet...");
					if (object instanceof PosPack)
					{
						System.out.println("Player with ID: " + playerWithId(connection.getID()).getID() + " is moving.");
						PosPack pos = (PosPack) object;
						playerWithId(connection.getID()).updatePos(pos);
					}
				}
				});

		server.addListener(new Listener() {
				public void connected(Connection connection)
			    	{
				//connection.sendTCP(new float[] {5.0f, 6.0f, 7.0f, 8.0f});
					System.out.println("Player connecting to server...");
					ServerPlayer newPlayer = new ServerPlayer(connection.getID());
					players.add(newPlayer);
					System.out.println("Player connected to server with ID: " + newPlayer.getID()); 
            			}
    		});
	

		return true;
	}
}



Hopefully it's something simple :S

Any help is appreciated!

Advertisement


colby@monkeybuckets ~/attempt/core/src/com/evergeen/attempt $ sudo javac -cp ".:kryonet-2.21-all.jar" GameServer.java PosPack.java ServerPlayer.java
colby@monkeybuckets ~/attempt/core/src/com/evergeen/attempt $ sudo java -cp ".:kryonet-2.21-all.jar" GameServer

You should not compile the code in the individual directories (com/evergeen/attempt), you would compile outside of the package (which is com.evergeen.attempt), test something like this


colby@monkeybuckets ~/attempt/core/src $ sudo javac -cp ".:kryonet-2.21-all.jar" ./com/evergeen/attempt/GameServer.java ./com/evergeen/attempt/PosPack.java ./com/evergeen/attempt/ServerPlayer.java
colby@monkeybuckets ~/attempt/core/src $ sudo java -cp ".:kryonet-2.21-all.jar" com.evergeen.attempt.GameServer

Ensure to place the kryonet jar accordingly. For more information look at the java doc (e.g. how to compile whole code branches etc.). Here is an example to compile some test program.

Wow, that was very helpful! Thanks a lot. It worked!

EDIT: The link was also helpful... Thanks agin.


colby@monkeybuckets ~/attempt/core/src/com/evergeen/attempt $ sudo javac -cp ".:kryonet-2.21-all.jar" GameServer.java PosPack.java ServerPlayer.java
colby@monkeybuckets ~/attempt/core/src/com/evergeen/attempt $ sudo java -cp ".:kryonet-2.21-all.jar" GameServer

Why are you compiling and running the code using sudo? You shouldn't need root permissions to do normal software development tasks.


colby@monkeybuckets ~/attempt/core/src/com/evergeen/attempt $ sudo javac -cp ".:kryonet-2.21-all.jar" GameServer.java PosPack.java ServerPlayer.java
colby@monkeybuckets ~/attempt/core/src/com/evergeen/attempt $ sudo java -cp ".:kryonet-2.21-all.jar" GameServer

Why are you compiling and running the code using sudo? You shouldn't need root permissions to do normal software development tasks.

I never needed this until the latest version of mint and it seemed odd to me as well. It doesn't work without it and I have no idea why, lol.

This topic is closed to new replies.

Advertisement