[GO] Until you can read the error log

Background

The other day, on Twitter, "[You are desperately not suitable for programming, so give up and do the job of putting dandelions on sashimi](https://megalodon.jp/2019-0105-0145-49/note.mu/ An article titled "kotofurumiya / n / n31d401fce782)" came around, but I recommend it because it was very interesting. There was a content in this that too many college students could not read the error log, and there were many sections that I could think of, so for the time being, I will focus on the Spigot Plugin and explain how to read the error log. I'm writing suddenly.

Let's look at the error log

Well, first of all, I can't talk without an error log. For the sake of explanation, I intentionally created a Plugin that raises NullPointerException.

QiitaPlugin.java


package com.github.siloneco.qiita;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class QiitaPlugin extends JavaPlugin implements Listener {

    @Override
    public void onEnable() {
        Bukkit.getPluginManager().registerEvents(this, this);
        Bukkit.getLogger().info(getName() + " enabled.");
    }

    @Override
    public void onDisable() {
        Bukkit.getLogger().info(getName() + " disabled.");
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent e) {
        Player p = null;
        p.sendMessage("test");
    }
}

With this code, when someone joins the server, it sends a null sendMessage and an error occurs. And the error log when this actually participated

latest.log


[14:23:24 ERROR]: Could not pass event PlayerJoinEvent to QiitaPlugin v1.0.0
org.bukkit.event.EventException: null
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
        at net.minecraft.server.v1_12_R1.PlayerList.onPlayerJoin(PlayerList.java:346) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
        at net.minecraft.server.v1_12_R1.PlayerList.a(PlayerList.java:166) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
        at net.minecraft.server.v1_12_R1.LoginListener.b(LoginListener.java:159) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
        at net.minecraft.server.v1_12_R1.LoginListener.e(LoginListener.java:57) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
        at net.minecraft.server.v1_12_R1.NetworkManager.a(NetworkManager.java:233) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
        at net.minecraft.server.v1_12_R1.ServerConnection.c(ServerConnection.java:140) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:845) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_231]
Caused by: java.lang.NullPointerException
        at com.github.siloneco.qiita.QiitaPlugin.onJoin(QiitaPlugin.java:26) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_231]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_231]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
        ... 14 more

The error log has been successfully generated.

How to read the error log

Let's read this log immediately. Here, I tried to color it for easy understanding. image.png ** The only part you really have to see is the dark colored part **. Even though it's such a long error log, there are so few places to read. Many people don't know this, so I can't read the error log. The procedure is very simple, but first you have to remember the package name of the Plugin you are making. Here it is com.github.siloneco.qiita.

1. Find the line that contains your package name

In the image above, it is the light blue part. Contains the package name of the Plugin you are making. The line starting with at describes the location of the error, so you only need to look at the package name used by your Plugin. Basically, it is often right after Caused by.

2. Look at the parentheses to the right of that line

In the image above, it is the green (QiitaPlugin.java:26) part. This shows the location of the error in the form of (filename: number of lines). In the case of this example, it means that an error has occurred at line 26 of the QiitaPlugin.java file.

3. See the reason for the error

Pay attention to the remaining green part. The green color at the top ( Could not pass event PlayerJoinEvent to QiitaPlugin v1.0.0) is irrelevant here, but I made it green for the time being because the reason for the error is sometimes written here. This time, there is a report that QiitaPlugin version 1.0.0 PlayerJoinEvent could not be processed normally. ** If you can't read English, please use Google Translate. It will be returned in Japanese that you can understand. ** ** Take a look at the following green color ( Caused by: java.lang.NullPointerException). This is obvious if you read it already. Caused by ~ means caused by ~, so in this case it can be understood as caused by java.lang.NullPointerException. In other words, the error that occurred is a java.lang.NullPointerException.

4. Let's organize

If you can't organize it in your head, you can write it on paper or notepad. Let's organize the information obtained in 1-3.

QiitaPlugin.There is an error on line 26 of java.
The error that occurred is java.lang.NullPointerException.

5. Find out what the error is

Not needed if you already know. Please fly to 6. The error that occurred this time is java.lang.NullPointerException. Let's dig this into Google and find out. Perhaps there will be many cases. If it does not appear, add "solution" etc. to the search word and it will basically appear. If that doesn't work, add "fix" etc. and read overseas articles. When reading various articles, it seems that NullPointerException is an error ** that occurs when you execute ** null with a dot (.) Connected to it **.

6. Based on the above, let's look at the problematic part

Let's take a look at the code in question

QiitaPlugin.java-24th line


p.sendMessage("test");

Well, in this line, the only thing that connects the dots is p. So it's very likely that p is null. Let's check

QiitaPlugin.java-Line 23-27th line


@EventHandler
public void onJoin(PlayerJoinEvent e) {
    Player p = null;
    p.sendMessage("test");
}

After all, null was assigned to p. It's solved by changing to ʻe.getPlayer () `.

Bonus: I fixed the error and got another error

This is a common story. Let's go back to 1 and resolve the new error.

Still can't solve!

If you have an error that you can't solve, it's faster to ask someone. There are many ways to do this, such as listening in the community or asking someone who is better than you. What I want you to be careful about at that time is

  1. Specify the environment
  2. Present the code
  3. Present the error log
  4. Describe other detailed information that may be relevant

Please be careful about these things and ask questions. ** Complex errors that cannot be resolved by looking only at the error log are likely to be related to the environment. ** For example, what is the Java version, what is the server version, what does the error occur, what changes were made if it worked fine before the change, etc. Needs a lot of information. ~~ Please stop if it seems to be broken even though you haven't done anything () ~~

Finally

This was Qiita's first post, but I hope this helps as many Plugin developers as possible. Themes and questions about Plugins are accepted in the Theme Box, so if you feel like it, please try pomponing. Well then.

change history

4/21 --I didn't need the title

Recommended Posts

Until you can read the error log
Until you can use the Google Speech API
You can read the analog meter with the example MNIST.
You can read the analog meter with the example MNIST.
Can you delete the file?
Try and learn iptables, until you can browse the web
Until you can use opencv with python
Until you install Caffe and run the sample
Until you use the Kaggle API with Colab
Until you run the changefinder sample in python
Until you can install blender and run it with python for the time being
Until you install Gauge and run the official sample
How to read the CBC (Pulp, python-mip) solver log
Until you can do simple image recognition with Jupyter
Read the OpenCV documentation
Until you install MySQL-python
read the tag assigned to you on ec2 with boto3
Until you can install your own Python library with pip
You who color the log to make it easier to see
What you can do with the Python standard library statistics
Parse the response so you can scrape Wantedly's own story