Class not found error but plugin compiles

Hello,

I’m receiving an error stating that my class PlayerPokemonEditor was not found. In the IDE, it compiles without issue and I am able to create objects and call function of that class, but at runtime it doesn’t work.

The class that calls the constructor and member function is defined as
`public class SizeIncreaseCommandExecutor implements CommandExecutor {
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {

    //get the closest player
    Player player = GetClosestPlayer(src);
    if(player == null) {
        src.sendMessage(Text.of("No available player"));
        return CommandResult.success();
    }
    else
        player.sendMessage(Text.of(TextColors.GREEN, "Size increase will incur on " + player.getName()));

    PlayerPokemonEditor playerEditor = new PlayerPokemonEditor(player.getName());
    String returnStatus = playerEditor.sizeInc();
    player.sendMessage(Text.of(returnStatus));

    return CommandResult.success();
}

}`

and the PlayerPokemonEditor class is defined as

`public PlayerPokemonEditor(String username) {
}

protected EntityPlayerMP player;
protected PlayerPartyStorage playerParty;

//Increases the size of the first pokemon in a players party by 1 if possible
//returns Error string on failure, or String success on success
public String sizeInc(){
}`

The calling class is in my Spongeforge module and the constructed class is in my Forge module. I’ve added the jar that is created by the Forge module as a dependency to the Spongeforge module by adding the line
compileOnly files("$rootDir/jetspoketools-forge/build/libs/jetspoketools-forge.jar")
to the dependencies section.

Does anyone know why the program can’t find the class even though it compiles fine?

Why do you have two modules? One for forge and one for sponge, all forge mods can use sponge and vice vera.

As for ClassNotFoundError. Typically there is a error above this, it will be either NoClassDefFound or SecurityException or something else.

If its NoClassDefFound then use a zip extractor to open your plugin and make sure that there is the file in the first place, if there is then its a java abnormalities (ill need to read the code you provided to work out that if its the case) if its not there then its a compilation error. Find out that to get further

I have two modules because that’s the way the intellij plugin set things up and I’m too new at making plugins to figure out how to put both into one. This was the only way I could manage to figure out and get things comiling

You’re right, it is a NoClassDefFound. I wasn’t sure how to read the error log lol. The actual error is:
[Server thread/ERROR] [Sponge]: Error occurred while executing command ‘jetsizeinc’ for source (command block): com/gmail/mathewcferry/jetspoketools/PlayerPokemonEditor
java.lang.NoClassDefFoundError: com/gmail/mathewcferry/jetspoketools/PlayerPokemonEditor

I’ll look into a zip extractor right now

Okay, the PlayerPokemonEditor was not within the .jar for the spongeforge plugin that was made. It was located inside the created Forge plugin. So now my question is, how do I get the PlayerPokemonEditor class into the Spongeforge produced jar, if that’s even possible given that that class exists in the Forge module.

I have only ever used gradle and maven to extract the contents of a single module so I don’t know without doing research and its almost midnight here so thats not happening XD

As for two modules for the setup, thats odd. Maybe a bug where it create a module per option you clicked? i havent developed a forge specific sponge pluginn since the olden days of Sponge so things may have changed since then or Im just forgetting the second module XD.

Personally I would combine the two modules (put the dependence of the sponge module into the dependencies of the forge one then move all your code over