AWT-EventQueue-0" java.lang.NullPointerException

Hello everyone,

I am trying to write a player for a game, but... :( The GUI of the game is given, so only the logic of movement! I wrote my algorithms, but I am having problems to make them work with the GUI and the functions there...

The loadPlayer method looks like this:

private static Player loadPlayer(String s)

{

if(s.endsWith(".class"))

{

int i = s.indexOf('.');

s = s.substring(0, i);

}

Object obj;

Class class1 = (new FileClassLoader("player")).loadClass(s);

obj = class1.newInstance();

return (Player)obj;

Exception exception;

exception;

System.out.println("@ENGINE: Player " + s + " can't be loaded!");

return null;

}

The Contructor of th file, that I'm trying to load looks like this:

public Player (Moves gameBoard) {

currentBoard = gameBoard;

}

And it loads a method minimax (Moves board)

The Moves.class file's Contructor:

Moves () {

pieces = new byte [50];

clearBoard();

}

and the clearBoard method is:

public void clearBoard () {

int i;

whitePieces = 20;

blackPieces = 20;

currentPlayer = BLACK;

for (i = 0; i < 20; i++)

pieces = BLACK;

for (i = 20; i < 30; i++)

pieces = EMPTY;

for (i = 30; i < 50; i++)

pieces = WHITE;

}

When I load the player, I recieve a couple of errors, which are:

Player PLAYER can't be loaded!

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

at eMad.Gui.actionPerformed(Unknown Source)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.AbstractButton.doClick(Unknown Source)

at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)

at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

If anyone can help with advice - please... :(

Greating to all

[2316 byte] By [keksya] at [2007-10-2 14:01:27]
# 1
Somewhere in an action listener, something is null.By the way, do you think this return null;is a good idea?
CeciNEstPasUnProgrammeura at 2007-7-13 12:08:35 > top of Java-index,Java Essentials,Java Programming...
# 2
And what is this supposed to be?Exception exception;exception;
CeciNEstPasUnProgrammeura at 2007-7-13 12:08:35 > top of Java-index,Java Essentials,Java Programming...
# 3

int i = s.indexOf('.');

s = s.substring(0, i);

// ...

Class class1 = (new FileClassLoader("player")).loadClass(s);

And whatever this is: are you sure that your classes don't have a package?

CeciNEstPasUnProgrammeura at 2007-7-13 12:08:35 > top of Java-index,Java Essentials,Java Programming...
# 4
And are in the classpath?
CeciNEstPasUnProgrammeura at 2007-7-13 12:08:35 > top of Java-index,Java Essentials,Java Programming...
# 5

Hello,

I do not agree too with these statements,but the situation is as follows:

I have to write only the player. The source for the GUI and a couple of other methods are given as .class files and "I am not supposed to know the source of these class files". That means that I should not change this code, only to adjust my player to work with this **** :(

I do not agree a lot of things in this too, but... what can I do :(

This

"Exception exception;

exception;

System.out.println("@ENGINE: Player " + s + " can't be loaded!");

return null;

"

I do not understand too... and "return null" is not very good solution, but... :(

Yes, right, my classes have a package and the name is the same as in the source given. The classpath works fine too!

Can be the problem this casting from Object to Player... may be something is wrong with my code... the superclass of my start-class (if I can say this) is java.lang.Object...

I checked everything three times already and can't see what the error could be :(

keksa at 2007-7-13 12:08:35 > top of Java-index,Java Essentials,Java Programming...
# 6

int i = s.indexOf('.');

s = s.substring(0, i);

}

Object obj;

Class class1 = (new FileClassLoader("player")).loadClass(s);

>> Player PLAYER can't be loaded!

You say your classes have a package. But the package is obviously ignored. You seem to try to load a class by unqualified class name only.

CeciNEstPasUnProgrammeura at 2007-7-13 12:08:35 > top of Java-index,Java Essentials,Java Programming...
# 7

I really do not understand what you mean :(

The root folder of the game is "Game" for example. There is a folder "player", where I should place my start-class, which contains only

public class Player extends player.Player{}

and within folder "player" I should have another folder "player name", where all my classes are!

So, all the source-files are in the package player

keksa at 2007-7-13 12:08:35 > top of Java-index,Java Essentials,Java Programming...