Question getInstance() why get null

LaumTop

New member
Oct 13, 2024
3
0
1
Hello. I tried to use getLogger(), but I got this error - 17:54:21 ERROR]: Error occurred while enabling Test1 v1.0 (Is it up to date?) java.lang.NullPointerException: Cannot invoke "LT.test2.Test2.getLogger()" because "this.test" is null. How I can fix it

Code here -

Java:
package LT.test1;

import LT.test2.Test2;
import org.bukkit.plugin.java.JavaPlugin;

public final class Test1 extends JavaPlugin {

Test2 test;

   @Override
public void onEnable() {
test = Test2.getInstance();
test.getLogger().info("test");
}

   @Override
public void onDisable()
{

}
}

YAML:
   name: Test1
   version: '1.0'
   main: LT.test1.Test1
   api-version: '1.20'
   depend: [test2]

Second plugin
Java:
package LT.test2;

import org.bukkit.plugin.java.JavaPlugin;

public final class Test2 extends JavaPlugin {

private static Test2 instance;

   @Override
public void onEnable() {
instance = this;

}

public static Test2 getInstance()
{
return instance;
}


   @Override
public void onDisable() {
// Plugin shutdown logic
}
}
YAML:
   name: test2
   version: '1.0'
   main: LT.test2.Test2
   api-version: '1.20'

Server log
Code:
[13:57:11] [ServerMain/INFO]: Environment: Environment[sessionHost=https://sessionserver.mojang.com, servicesHost=https://api.minecraftservices.com, name=PROD]
[13:57:12] [ServerMain/INFO]: Loaded 1174 recipes
[13:57:12] [ServerMain/INFO]: Loaded 1271 advancements
[13:57:12] [Server thread/INFO]: Starting minecraft server version 1.20.4
[13:57:12] [Server thread/INFO]: Loading properties
[13:57:12] [Server thread/INFO]: This server is running Paper version git-Paper-398 (MC: 1.20.4) (Implementing API version 1.20.4-R0.1-SNAPSHOT) (Git: b700460)
[13:57:13] [Server thread/INFO]: Server Ping Player Sample Count: 12
[13:57:13] [Server thread/INFO]: Using 4 threads for Netty based IO
[13:57:13] [Server thread/WARN]: [!] The timings profiler has been enabled but has been scheduled for removal from Paper in the future.
    We recommend installing the spark profiler as a replacement: https://spark.lucko.me/
    For more information please visit: https://github.com/PaperMC/Paper/issues/8948
[13:57:13] [Server thread/INFO]: [ChunkTaskScheduler] Chunk system is using 1 I/O threads, 3 worker threads, and gen parallelism of 3 threads
[13:57:13] [Server thread/INFO]: Default game type: SURVIVAL
[13:57:13] [Server thread/INFO]: Generating keypair
[13:57:13] [Server thread/INFO]: Starting Minecraft server on *:25565
[13:57:13] [Server thread/INFO]: Using epoll channel type
[13:57:13] [Server thread/INFO]: Paper: Using libdeflate (Linux x86_64) compression from Velocity.
[13:57:13] [Server thread/INFO]: Paper: Using OpenSSL 3.0.x (Linux x86_64) cipher from Velocity.
[13:57:13] [Server thread/INFO]: [test2] Loading server plugin test2 v1.0
[13:57:13] [Server thread/INFO]: [Paper_Economy] Loading server plugin Paper_Economy v1.0
[13:57:13] [Server thread/INFO]: [Test1] Loading server plugin Test1 v1.0
[13:57:13] [Server thread/INFO]: [ChatGame] Loading server plugin ChatGame v1.0
[13:57:13] [Server thread/INFO]: [Kits] Loading server plugin Kits v1.0
[13:57:13] [Server thread/INFO]: [Regions] Loading server plugin Regions v1.0
[13:57:13] [Server thread/INFO]: [Basics] Loading server plugin Basics v1.0
[13:57:13] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
[13:57:13] [Server thread/INFO]: Preparing level "world"
[13:57:13] [Server thread/INFO]: Preparing start region for dimension minecraft:overworld
[13:57:13] [Server thread/INFO]: Time elapsed: 114 ms
[13:57:13] [Server thread/INFO]: Preparing start region for dimension minecraft:the_nether
[13:57:14] [Server thread/INFO]: Time elapsed: 1003 ms
[13:57:14] [Server thread/INFO]: Preparing start region for dimension minecraft:the_end
[13:57:14] [Server thread/INFO]: Time elapsed: 19 ms
[13:57:14] [Server thread/INFO]: [test2] Enabling test2 v1.0
[13:57:14] [Server thread/INFO]: [Paper_Economy] Enabling Paper_Economy v1.0
[13:57:14] [Server thread/INFO]: [Test1] Enabling Test1 v1.0
[13:57:14] [Server thread/ERROR]: Error occurred while enabling Test1 v1.0 (Is it up to date?)
java.lang.NullPointerException: Cannot invoke "LT.test2.Test2.getLogger()" because "this.test" is null
    at LT.test1.Test1.onEnable(Test1.java:13) ~[test1-1.0.jar:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:281) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
    at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:190) ~[paper-1.20.4.jar:git-Paper-398]
    at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:104) ~[paper-1.20.4.jar:git-Paper-398]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:507) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.craftbukkit.v1_20_R3.CraftServer.enablePlugin(CraftServer.java:637) ~[paper-1.20.4.jar:git-Paper-398]
    at org.bukkit.craftbukkit.v1_20_R3.CraftServer.enablePlugins(CraftServer.java:548) ~[paper-1.20.4.jar:git-Paper-398]
    at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:670) ~[paper-1.20.4.jar:git-Paper-398]
    at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:430) ~[paper-1.20.4.jar:git-Paper-398]
    at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:308) ~[paper-1.20.4.jar:git-Paper-398]
    at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1129) ~[paper-1.20.4.jar:git-Paper-398]
    at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:318) ~[paper-1.20.4.jar:git-Paper-398]
    at java.lang.Thread.run(Thread.java:1583) ~[?:?]
[13:57:14] [Server thread/INFO]: [Test1] Disabling Test1 v1.0
[13:57:14] [Server thread/INFO]: [ChatGame] Enabling ChatGame v1.0
[13:57:14] [Server thread/ERROR]: [ChatGame] Paper_Economy plugin not found or incompatible!
[13:57:14] [Server thread/INFO]: [ChatGame] Disabling ChatGame v1.0
[13:57:14] [Server thread/INFO]: [Kits] Enabling Kits v1.0
[13:57:14] [Server thread/INFO]: [Kits] Started
[13:57:15] [Server thread/INFO]: [Regions] Enabling Regions v1.0
[13:57:15] [Server thread/INFO]: [Basics] Enabling Basics v1.0
[13:57:15] [Server thread/INFO]: [Basics] Starting...
[13:57:15] [Server thread/INFO]: Running delayed init tasks
[13:57:15] [Server thread/INFO]: Done (2.439s)! For help, type "help"
[13:57:15] [Server thread/INFO]: Timings Reset
[13:57:16] [Server thread/INFO]: Stopping server
[13:57:16] [Server thread/INFO]: [Basics] Disabling Basics v1.0
[13:57:16] [Server thread/INFO]: [Regions] Disabling Regions v1.0
[13:57:16] [Server thread/INFO]: [Kits] Disabling Kits v1.0
[13:57:16] [Server thread/INFO]: [Paper_Economy] Disabling Paper_Economy v1.0
[13:57:16] [Server thread/INFO]: [test2] Disabling test2 v1.0
[13:57:16] [Server thread/INFO]: Saving players
[13:57:16] [Server thread/INFO]: Saving worlds
[13:57:16] [Server thread/INFO]: Saving chunks for level 'ServerLevel[world]'/minecraft:overworld
[13:57:16] [Server thread/INFO]: [ChunkHolderManager] Waiting 60s for chunk system to halt for world 'world'
[13:57:16] [Server thread/INFO]: [ChunkHolderManager] Halted chunk system for world 'world'
[13:57:16] [Server thread/INFO]: [ChunkHolderManager] Saving all chunkholders for world 'world'
[13:57:17] [Server thread/INFO]: [ChunkHolderManager] Saved 529 block chunks, 529 entity chunks, 0 poi chunks in world 'world' in 0.63s
[13:57:17] [Server thread/INFO]: ThreadedAnvilChunkStorage (world): All chunks are saved
[13:57:17] [Server thread/INFO]: Saving chunks for level 'ServerLevel[world_nether]'/minecraft:the_nether
[13:57:17] [Server thread/INFO]: [ChunkHolderManager] Waiting 60s for chunk system to halt for world 'world_nether'
[13:57:17] [Server thread/INFO]: [ChunkHolderManager] Halted chunk system for world 'world_nether'
[13:57:17] [Server thread/INFO]: [ChunkHolderManager] Saving all chunkholders for world 'world_nether'
[13:57:17] [Server thread/INFO]: [ChunkHolderManager] Saved 529 block chunks, 529 entity chunks, 0 poi chunks in world 'world_nether' in 0.36s
[13:57:17] [Server thread/INFO]: ThreadedAnvilChunkStorage (DIM-1): All chunks are saved
[13:57:17] [Server thread/INFO]: Saving chunks for level 'ServerLevel[world_the_end]'/minecraft:the_end
[13:57:17] [Server thread/INFO]: [ChunkHolderManager] Waiting 60s for chunk system to halt for world 'world_the_end'
[13:57:17] [Server thread/INFO]: [ChunkHolderManager] Halted chunk system for world 'world_the_end'
[13:57:17] [Server thread/INFO]: [ChunkHolderManager] Saving all chunkholders for world 'world_the_end'
[13:57:17] [Server thread/INFO]: [ChunkHolderManager] Saved 529 block chunks, 529 entity chunks, 0 poi chunks in world 'world_the_end' in 0.07s
[13:57:17] [Server thread/INFO]: ThreadedAnvilChunkStorage (DIM1): All chunks are saved
[13:57:17] [Server thread/INFO]: ThreadedAnvilChunkStorage: All dimensions are saved
[13:57:17] [Server thread/INFO]: Flushing Chunk IO
[13:57:17] [Server thread/INFO]: Closing Thread Pool
[13:57:17] [Server thread/INFO]: Closing Server
 
Version Output
Paper version git-Paper-398 (MC: 1.20.4) (Implementing API version 1.20.4-R0.1-SNAPSHOT) (Git: b700460)

LaumTop

New member
Oct 13, 2024
3
0
1
Some more info. If I in getInstance() return for example int and number 1. I get this value, and I dont get Null exception