#A is null

1 messages · Page 1 of 1 (latest)

silent arch
#

Can you send me the error?

#

@distant elbow

distant elbow
#
Cannot read the array length because "a" is null
silent arch
#

Is that the entire error?

#

And where did you get this error

distant elbow
#

its when I run the command /minigames add <lobby/arena> <minigame> <worlds>
The error appears in the console

#

there is more to the error but that was the only bit that seemed relevant

silent arch
#

You’re almost correct, cuz in the console it says where the error is

#

so you can see what you need to change

distant elbow
#

here is more of the console output but I cant see where it says where the error is:

Caused by: java.lang.NullPointerException: Cannot read the array length because "a" is null
        at java.util.Arrays.fill(Arrays.java:3429) ~[?:?]
        at com.nikolaipatrick.MinigamesManager.MinigamesManager.onCommand(MinigamesManager.java:54) ~[MinigamesManager-1.0.0-SNAPSHOT.jar:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]

silent arch
#

its enough

#

see this bit:
com.nikolaipatrick.MinigamesManager.MinigamesManager.onCommand(MinigamesManager.java:54) ~[MinigamesManager-1.0.0-SNAPSHOT.jar:?]

#

is that your domain?

distant elbow
#

com.nikolaipatrick is

silent arch
#

ok

#

so

#

MinigamesManager.onCommand(MinigamesManager.java:54) this bit says that the error is in your MinigamesManager class, on line 54

distant elbow
#

ahhh yes i see

#

ok I think i might have found the problem

#

on line 54: minigameName = args[2];

silent arch
#

is args[2] in bounds?

distant elbow
#

to run the command properly, it should be but I see what i have done wrong

silent arch
#

ok, gl then, and have fun

#

for any further help you cvan always just DM me

distant elbow
#

thanks! ill keep that in mind

#

ahh I got mixed up

#

i thought i found the problem cos i was thinking that minigameName was a string array

#

was meant to be a string array

#

but it should be a string which is what it is now

#

so I'm still not sure why there is a problem

#

you there, @silent arch ?

silent arch
#

ye

#

can you send the updated code?

#

@distant elbow

distant elbow
#

yes one sec

silent arch
#

what is the problem rn?

#

i see

#

you dont implement CommandExecutor

#

you do need to import 2 things

distant elbow
#

ok I'll give that a try

silent arch
#

does it work?

distant elbow
#

I still seem to be getting the "a" is null error

silent arch
#

on the same line?

distant elbow
#

no its line 60 this time i think

#
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.lang.NullPointerException: Cannot read the array length because "a" is null
        at java.util.Arrays.fill(Arrays.java:3429) ~[?:?]
        at com.nikolaipatrick.MinigamesManager.MinigamesManager.onCommand(MinigamesManager.java:60) ~[MinigamesManager-1.0.0-SNAPSHOT.jar:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
        ... 21 more

silent arch
#

ye, it is

#

whats on line 60?

distant elbow
#

Arrays.fill(worldNames, null);

silent arch
#

that was commented right?

distant elbow
#

its not commented at the moment

silent arch
#

what do you use it for?

distant elbow
#

in case the user is running the command more than once, worldNames can be used more than once

silent arch
#

the vars are not static right?

distant elbow
#

what do you mean?

silent arch
#

did you declare worldNames static?

distant elbow
#

oh

#

no i didnt

silent arch
#

than its fine, and you do should not need that line

distant elbow
#

but say the user used the add command to add two worlds in the same command and then used the add command a second time but only added one world in the same command

#

there would be nothing to clear the second world from the previous command

silent arch
#

i do not understand you, but do you mean that the command copies the old worlds and putrs them into a new one to add it

#

cuz rn, if soimone uses the command a second time, you haven't stored the worlds of the first command

distant elbow
silent arch
#

no, as every time you execute a command it makes a new class

#

i think

distant elbow
#

ohh i see

#

so I removed the array.fill and now I have this error again in my console:

Caused by: java.lang.NullPointerException: Cannot store to object array because "this.worldNames" is null
        at com.nikolaipatrick.MinigamesManager.MinigamesManager.onCommand(MinigamesManager.java:62) ~[MinigamesManager-1.0.0-SNAPSHOT.jar:?]

heres my current code: https://paste.md-5.net/hukacucufo.java

#

but its getting late for me so I need to go

silent arch
distant elbow
#

so I changed my code a bit so it only supports adding one world per command but i get this error in the console:

Caused by: java.lang.NullPointerException: Cannot store to object array because "this.worldName" is null
        at com.nikolaipatrick.MinigamesManager.MinigamesManager.onCommand(MinigamesManager.java:57) ~[MinigamesManager-1.0.0-SNAPSHOT.jar:?]

here is my current code: https://paste.md-5.net/webalacuhi.java

silent arch
#

Is that the only file?

silent arch
#

@distant elbow

distant elbow
#

yes that is the only file

silent arch
#

Ok, illtry to fuc it!

#

Fix

distant elbow
#

thank you

silent arch
#

when do you get the error?

distant elbow
#

when I run /minigames add

#

I think I might have just fixed it

#

I added this line to make the array an object:

worldName = new String[1];
silent arch
#

Remove the 1

#

Otherwise it will not get the memory needed

distant elbow
#

the compiler doesnt work if i do that but its solved the prblem

silent arch
#

So it works now ?

distant elbow
#

yes

#

well kinda

#

it fixed that problem but I have another question

silent arch
#

Tell me

distant elbow
#

when I use this in my code:

existingWorlds[0] = getConfig().getList(minigameName + ".lobbies");

the compiler throws an error saying:

Incompatible types. Found: 'java.util.List<capture<?>>', required: 'java.lang.String'
silent arch
#

Use getStringList() is it is a list of strings

distant elbow
#

ah ok

#

hmm

#

it still gives the same error as before

silent arch
#

At the same line?

distant elbow
#

yes

silent arch
#

Could you send the entire error?

distant elbow
#

thats the entire error

silent arch
#

In intellij or console

distant elbow
#

intellij

#

haha how did you know I was using intellij?

silent arch
#

It said it on your dc

distant elbow
#

ooh right it does I must have turned that on

silent arch
#

And its also industry standard

#

Is it a warning or an error

distant elbow
#

an error

silent arch
#

M can you send the line?

#

On wich the error is

distant elbow
#

this is the line with the error:

existingWorlds[0] = getConfig().getStringList(minigameName + ".lobbies");

but I'm only putting a 0 in existingWorlds to test if it works but I plan on making it into a for loop

silent arch
#

Try existingWorlds.

#

Add or put

#

Or smth like that

distant elbow
#

without the [0] ?

silent arch
#

Ye

distant elbow
#

it gives the same error

silent arch
#

F

#

Ehm

#

I gtg

#

I’m going to my GF

#

Cya!

distant elbow
#

bye!

silent arch
#

Much success btw