如何通过实体修复Minecraft 1.12空指针异常错误?

问题描述 投票:-1回答:1

我一直试图修复它,很困惑,每次打开它时,它都会崩溃,并显示相同的错误消息“ java.lang.NullPointerException”,以下是完整的错误消息:

net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from The Human Tools Mod (sword)
Caused by: java.lang.NullPointerException
    at net.minecraftforge.fml.common.registry.EntityRegistry.doModEntityRegistration(EntityRegistry.java:207)
    at net.minecraftforge.fml.common.registry.EntityRegistry.registerModEntity(EntityRegistry.java:192)
    at com.example.examplemod.init.EntityInit.registerEntity(EntityInit.java:18)
    at com.example.examplemod.init.EntityInit.registerEntities(EntityInit.java:13)
    at com.example.examplemod.util.handlers.RegistryHandler.preInitRegistries(RegistryHandler.java:62)
    at com.example.examplemod.util.ExampleMod.preInit(ExampleMod.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:626)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
    at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
    at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
    at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
    at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
    at com.google.common.eventbus.EventBus.post(EventBus.java:217)
    at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:218)
    at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:196)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
    at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
    at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
    at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
    at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
    at com.google.common.eventbus.EventBus.post(EventBus.java:217)
    at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:135)
    at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:627)
    at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:252)
    at net.minecraft.client.Minecraft.init(Minecraft.java:513)
    at net.minecraft.client.Minecraft.run(Minecraft.java:421)
    at net.minecraft.client.main.Main.main(Main.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
    at GradleStart.main(GradleStart.java:25)**

以及我的一些代码:

正在尝试注册实体的代码:

public class EntityInit
{
    public static void registerEntities()
    {
        registerEntity("human", EntityHuman.class, ExampleMod.ENTITY_HUMAN, 50, 3093151, 16287108);
    }

    private static void registerEntity(String name, Class<? extends Entity> entity, int id, int range, int color1, int color2 )
    {
        EntityRegistry.registerModEntity(new ResourceLocation("sword:" + name), entity, name, id, ExampleMod.instance, range, 1, true, color1, color2);
    }
}
java entity minecraft minecraft-forge
1个回答
-1
投票

您可能想像在世界上一样都不喜欢时尝试运行此代码,这就是为什么它崩溃的原因,但您始终可以在方法内部添加try / catch。

try {
    //Your code here
} catch (NullPointerException e) {

}

喜欢这个:

public static void registerEntities()
{
    try {
        //Your code here
    } catch (NullPointerException e) {

    }
}
© www.soinside.com 2019 - 2024. All rights reserved.