MethodError: no method matching getindex(::Nothing, ::String)

Hi, I’m trying to do an iteration, where I use a dictionary that gives me an array with values (“players”) and an array with weights (“weights”) with the same size, to make a sample. When I do it outside of iteration it has no problem, but on the first iteration it throws me this error: MethodError: no method matchinggetindex (:: Nothing, :: String)

Here is the code that works outside the iteration, but inside throws the error above.

new_player = sample(my_dict["2499719"][1631]["Z4.2"][14763]["players"],
                        Weights(my_dict["2499719"][1631]["Z4.2"][14763]["weights"]))

The complete info of the error is:

MethodError(getindex, (nothing, "2499719"), 0x0000000000006d1a)
MethodError: no method matching getindex(::Nothing, ::String)

Stacktrace:
 [1] my_function(::String, ::Int64, ::Int64) at .\In[44]:91
 [2] top-level scope at In[45]:1
 [3] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091

I hope you can help me!

Your my_dict variable is nothing.

For more help, please post a self contained, minimum (non-)working example.

2 Likes

I did not understand, how is it nothing? if it worked outside the for loop.
PS: your link doesn’t work.

how?

can you show a runnable code?

1 Like