Jump to content

[1.10.2][SOLVED] My own mod API crashes outside of workspace


yolp900

Recommended Posts

I am trying to test my mod outside of IntelliJ Idea. I built my mod using the Gradle task built into IntelliJ and placed the jar file I got (not the source jar) in the "mods" folder. When I load up Minecraft, I end up with this crash:

 

 

 

java.lang.NoClassDefFoundError: com/yolp900/itsjustacharm/common/items/ItemAffinityHolder

at java.lang.Class.getDeclaredFields0(Native Method)

at java.lang.Class.privateGetDeclaredFields(Class.java:2575)

at java.lang.Class.privateGetPublicFields(Class.java:2606)

at java.lang.Class.getFields(Class.java:1549)

at net.minecraftforge.fml.common.registry.ObjectHolderRegistry.scanClassForFields(ObjectHolderRegistry.java:133)

at net.minecraftforge.fml.common.registry.ObjectHolderRegistry.scanTarget(ObjectHolderRegistry.java:103)

at net.minecraftforge.fml.common.registry.ObjectHolderRegistry.findObjectHolders(ObjectHolderRegistry.java:61)

at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:604)

at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:255)

at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:439)

at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:351)

at net.minecraft.client.main.Main.main(SourceFile:124)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

Caused by: java.lang.ClassNotFoundException: com.yolp900.itsjustacharm.common.items.ItemAffinityHolder

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

... 18 more

Caused by: java.lang.NoClassDefFoundError: com/yolp900/itsjustacharm/api/affinities/IAffinityHolderItem

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(ClassLoader.java:760)

at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:182)

... 20 more

Caused by: java.lang.ClassNotFoundException: com.yolp900.itsjustacharm.api.affinities.IAffinityHolderItem

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

... 24 more

Caused by: java.lang.NullPointerException

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:182)

... 26 more

 

 

ItemAffinityHolder implements the interface IAffinityHolderItem which is in my mod's api.

 

From what I understand, the api class I use isn't found. I thought it is packaged with the mod, as it is a part of it and it is in "src.main.java.com.yolp900.itsjustacharm.api" folder inside of the source folders, but I must be wrong. How can I fix this crash and run my mod outside of the workspace?

 

Thanks in advance!

Link to comment
Share on other sites

IAffinityHolderItem - The interface in the api that's not found.

 

package com.yolp900.itsjustacharm.api.affinities;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

import javax.annotation.Nonnull;
import java.util.List;

public interface IAffinityHolderItem {

int getMaxAmountOfStoredAffinities(@Nonnull ItemStack stack, EntityPlayer player, World world);

int getCurrentAffinityIndex(@Nonnull ItemStack stack, EntityPlayer player, World world);

void setCurrentAffinityIndex(@Nonnull ItemStack stack, int index, EntityPlayer player, World world);

List<IAffinity> getStoredAffinities(@Nonnull ItemStack stack, EntityPlayer player, World world);

IAffinity getStoredAffinity(@Nonnull ItemStack stack, int index, EntityPlayer player, World world);

boolean storeAffinity(@Nonnull ItemStack stack, @Nonnull IAffinity affinity, EntityPlayer player, World world);

boolean removeAffinity(@Nonnull ItemStack stack, int index, EntityPlayer player, World world);

}

 

ItemAffinityHolder - the item which implements the interface.

 

package com.yolp900.itsjustacharm.common.items;

import com.yolp900.itsjustacharm.api.IJCConstants;
import com.yolp900.itsjustacharm.api.ItsJustaCharmAPI;
import com.yolp900.itsjustacharm.api.affinities.IAffinity;
import com.yolp900.itsjustacharm.api.affinities.IAffinityHolderItem;
import com.yolp900.itsjustacharm.common.affinities.ModAffinities;
import com.yolp900.itsjustacharm.common.items.base.ModItem;
import com.yolp900.itsjustacharm.util.NBTHelper;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;

public class ItemAffinityHolder extends ModItem implements IAffinityHolderItem {

public ItemAffinityHolder() {
	super(IJCConstants.Items.AffinityHolder);
	setMaxStackSize(1);
}

@Override
public int getMaxAmountOfStoredAffinities(@Nonnull ItemStack stack, EntityPlayer player, World world) {
	return ItsJustaCharmAPI.Affinities.affinities.size();
}

@Override
public int getCurrentAffinityIndex(@Nonnull ItemStack stack, EntityPlayer player, World world) {
	return NBTHelper.getInt(stack, IJCConstants.NBT.CURRENT_AFFINITY_INDEX);
}

@Override
public void setCurrentAffinityIndex(@Nonnull ItemStack stack, int index, EntityPlayer player, World world) {
	NBTHelper.setInt(stack, IJCConstants.NBT.CURRENT_AFFINITY_INDEX, index);
}

@Override
public List<IAffinity> getStoredAffinities(@Nonnull ItemStack stack, EntityPlayer player, World world) {
	List<IAffinity> storedAffinities = new ArrayList<IAffinity>(getMaxAmountOfStoredAffinities(stack, player, world));
	for (int i = 0; i < getMaxAmountOfStoredAffinities(stack, player, world); i++) {
		IAffinity currAffinity = getStoredAffinity(stack, i, player, world);
		if (currAffinity != null) {
			storedAffinities.add(currAffinity);
		}
	}
	return storedAffinities;
}

@Override
public IAffinity getStoredAffinity(@Nonnull ItemStack stack, int index, EntityPlayer player, World world) {
	int maxAmount = getMaxAmountOfStoredAffinities(stack, player, world);
	if (index < 0 || index >= maxAmount) {
		return null;
	}
	String affinityName = NBTHelper.getString(stack, IJCConstants.NBT.STORED_AFFINITY(index));
	if (affinityName == null || affinityName.equals("")) {
		return null;
	}
	return ItsJustaCharmAPI.Affinities.getAffinityFromName(affinityName);
}

@Override
public boolean storeAffinity(@Nonnull ItemStack stack, @Nonnull IAffinity affinity, EntityPlayer player, World world) {
	List<IAffinity> storedAffinities = getStoredAffinities(stack, player, world);

	if (storedAffinities == null || storedAffinities.size() == 0) {
		NBTHelper.setString(stack, IJCConstants.NBT.STORED_AFFINITY(0), affinity.getName());
	}

	if (storedAffinities != null) {
		for (IAffinity storedAffinity : storedAffinities) {
			if (storedAffinity != null && storedAffinity == affinity) {
				return false;
			}
		}
		for (int i = 0; i < storedAffinities.size(); i++) {
			if (storedAffinities.get(i) == null) {
				storeAffinity(stack, affinity, i);
				return true;
			}
		}
	}

	return false;
}

@Override
public boolean removeAffinity(@Nonnull ItemStack stack, int index, EntityPlayer player, World world) {
	removeAffinity(stack, index);
	return true;
}

private void storeAffinity(@Nonnull ItemStack stack, @Nonnull IAffinity affinity, int index) {
	NBTHelper.setString(stack, IJCConstants.NBT.STORED_AFFINITY(index), affinity.getName());
}

private void removeAffinity(@Nonnull ItemStack stack, int index) {
	NBTHelper.setString(stack, IJCConstants.NBT.STORED_AFFINITY(index), "");
}

@Override
@Nonnull
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	if (stack == null || !(stack.getItem() instanceof ItemAffinityHolder))
		return super.onItemUse(stack, player, world, pos, hand, facing, hitX, hitY, hitZ);
	IAffinityHolderItem affinityHolder = (IAffinityHolderItem)stack.getItem();
	affinityHolder.setCurrentAffinityIndex(stack, 0, player, world);

	Block block = world.getBlockState(pos).getBlock();
	if (block == Blocks.GRASS) {
		affinityHolder.storeAffinity(stack, ModAffinities.Earth, player, world);
	} else if (block == Blocks.STONE) {
		affinityHolder.storeAffinity(stack, ModAffinities.Block, player, world);
	} else if (block == Blocks.NETHERRACK) {
		affinityHolder.storeAffinity(stack, ModAffinities.Fire, player, world);
	} else if (block == Blocks.ICE) {
		affinityHolder.storeAffinity(stack, ModAffinities.Water, player, world);
	} else if (block == Blocks.REEDS) {
		affinityHolder.storeAffinity(stack, ModAffinities.Air, player, world);
	}
	return super.onItemUse(stack, player, world, pos, hand, facing, hitX, hitY, hitZ);
}

}

 

I really don't think it's the methods themselves which are the problems. I think the api is not packaged with the rest of the mod. I might be wrong. I don't know...

Link to comment
Share on other sites

What's your modid, and is it all lower case? If you're working in Windoze, the file system will ignore case while in your dev environment. As soon as you compile into a jar, you move into a case-sensitive environment. Class-not-found errors are usually case mismatches or reobfuscation failures. Put at least two pairs of eyes on literal matching of you class and path names (these are things that can "look right" at first and second glance before palm finally hits face).

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Ok, I'm trying to find any reason for this happening, and I'm just failing to do so. The crash log says it can't find a class which is in the jar file. I thought it's because it's in the api, but previous api classes worked and I hadn't changed anything, just added content. I'm really not sure what to do in order to solve this. Does anybody have an idea? I'm pretty much lost...

Link to comment
Share on other sites

First of all - thanks for the reply!  :)

 

I am looking at many open source mods and I don't see any dependencies on their API. I don't really know how to reference the API correctly in the DEPENDENCIES area in the mod file. Is there an example of how to do so?

 

And about the ObjectHolder: If I don't initialize the objects (items and blocks), the code complains that they might have not been initiated. Do I need to put the annotation on every object?

Link to comment
Share on other sites

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

 

I don't understand how this helps me. This is how one adds dependencies to outside mods. I'm looking for getting the dependency for the API:

For one, your Mod does not actually depend on your API, so FML is free to load the API after your mod, making your mod crash.

 

and making sure that the mod is loading before the API.

 

That's the problem with annotation-magic for you, the compiler does not understand it. Either initialize the fields to null or make them not-final.

 

Since I don't use the ObjectHolder features in the code, and I don't see any use of it in other mods (so I don't really know how it works), I decided to remove it from my classes.

Now the mod crashed and the crash log says that it can't find the tileEntity that is implementing an interface from the API. I passed the preInitialization stage when I removed the ObjectHolder annotation, but now it crashed in the init stage. I think it's related to the "mod is loaded before the API", but I still don't know how to make my mod load before the API.. Should I add "required-after:ItsJustaCharmAPI"? Will that work even though it's a class and not another mod?

Link to comment
Share on other sites

Ok, I added "required-after:ItsJustaCharmAPI" to my dependencies. I now get to the init stage and then crash:

 

 

 

net.minecraftforge.fml.common.LoaderException: java.lang.NoClassDefFoundError: com/yolp900/itsjustacharm/common/tileEntities/TileEntityConstructionTable

at net.minecraftforge.fml.common.LoadController.transition(LoadController.java:186)

at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:610)

at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:255)

at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:439)

at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:351)

at net.minecraft.client.main.Main.main(SourceFile:124)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

Caused by: java.lang.NoClassDefFoundError: com/yolp900/itsjustacharm/common/tileEntities/TileEntityConstructionTable

at com.yolp900.itsjustacharm.common.blocks.ModBlocks.registerBlocks(ModBlocks.java:21)

at com.yolp900.itsjustacharm.common.CommonProxy.preInit(CommonProxy.java:32)

at com.yolp900.itsjustacharm.client.ClientProxy.preInit(ClientProxy.java:32)

at com.yolp900.itsjustacharm.ItsJustaCharm.preInit(ItsJustaCharm.java:31)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:595)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)

at com.google.common.eventbus.EventBus.post(EventBus.java:275)

at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:239)

at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:217)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)

at com.google.common.eventbus.EventBus.post(EventBus.java:275)

at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:142)

at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:607)

... 10 more

Caused by: java.lang.ClassNotFoundException: com.yolp900.itsjustacharm.common.tileEntities.TileEntityConstructionTable

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

... 41 more

Caused by: java.lang.NoClassDefFoundError: com/yolp900/itsjustacharm/api/affinities/IAffinityHolderTile

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(ClassLoader.java:760)

at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:182)

... 43 more

Caused by: java.lang.ClassNotFoundException: com.yolp900.itsjustacharm.api.affinities.IAffinityHolderTile

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

... 47 more

Caused by: java.lang.NullPointerException

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:182)

... 49 more

 

 

 

Now it can't find an other interface in the api, and can't init my TileEntity. I don't have an ObjectHolder annotation so I can't see what's causing this.

Link to comment
Share on other sites

 

I don't understand how this helps me. This is how one adds dependencies to outside mods. I'm looking for getting the dependency for the API

 

Dude.  Both of those mod references are my own mods. HardLib contains my API.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

It contains it just like my mod contains my API, as far as I understand. You are setting a dependency for your mod which contains an API. I'm asking a different question - My mod contains my API (Again, as far as I understand), but It still crashes when trying to load classes from it outside of the dev area. I'm asking if I need to do something specific in order to get my mod to realize my API is there.

Link to comment
Share on other sites

My dependency argument is now:

required-after:Forge@[12.18.1.2053,];required-after:Baubles@[1.3.BETA8,];required-after:ItsJustaCharmAPI

 

My mod still crashes, now in the init stage (and not preInit), saying it can't find a class from the API. The class is in the jar file, I'm depending on the API and I'm not using ObjectHolder. I don't know the reason for that crash, and that's what I'm looking for...

Link to comment
Share on other sites

Mod IDs are all lower case.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.