MethodError: no method matching Array(::Type{Int64}, ::Int64) -- New Julia User

Hello, I am new here and new to Julia. I can’t figure out how to address this error; I’ve tried the suggestions in similar threads and have been unable to find a solution. Help is appreciated.


function(form_one)
    println("function was here")
end

function creator(x, y, path_input1, path_input2, formulation, path_to_output)

    ###### MethodError HERE ***************************
    w = Array(Int64, 0)

    c = Array(Int64, 0)

    d = Array(Int64, 0)

# more code follows

end

x=100
y=7
formulation = form_one
#paths defined

creator(x, y, path_input1, path_input2, formulation, path_to_output) 

When I run this, I get the following error and stacktrace:

ERROR: LoadError: MethodError: no method matching Array(::Type{Int64}, ::Int64)
Closest candidates are:
  Array(::LinearAlgebra.UniformScaling, ::Integer, ::Integer) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\LinearAlgebra\src\uniformscaling.jl:395
Stacktrace:
 [1] creator(::Int64, ::Int64, ::String, ::String, ::Function, ::String) at c:\PATH\question.jl:9
 [2] top-level scope at c:\PATH\question.jl:27
 [3] include_string(::Module, ::String, ::String) at .\loading.jl:1064
 [4] (::getfield(Main._vscodeserver, Symbol("##9#12")){String,Int64,Int64,String})() at c:\PATH\julialang.language-julia-0.13.1\scripts\terminalserver\terminalserver.jl:153
 [5] withpath(::getfield(Main._vscodeserver, Symbol("##9#12")){String,Int64,Int64,String}, ::String) at c:\PATH\julialang.language-julia-0.13.1\scripts\terminalserver\repl.jl:62
 [6] (::getfield(Main._vscodeserver, Symbol("##8#11")){String,Int64,Int64,String})() at c:\PATH\julialang.language-julia-0.13.1\scripts\terminalserver\terminalserver.jl:152
 [7] hideprompt(::getfield(Main._vscodeserver, Symbol("##8#11")){String,Int64,Int64,String}) at c:\PATH\julialang.language-julia-0.13.1\scripts\terminalserver\repl.jl:28
 [8] macro expansion at c:\PATH\julialang.language-julia-0.13.1\scripts\terminalserver\terminalserver.jl:148 [inlined]
 [9] (::getfield(Main._vscodeserver, Symbol("##7#10")))() at .\task.jl:268
in expression starting at c:\PATH\question.jl:27

I’m very confused why I can’t get this to work – it seems simple but clearly I am missing something. I also tried this in Julia 1.4.2 running on Google Colab, no dice. Thanks for taking a look!

Instead of Array(Int, 0), use Array{Int}(undef, 0) or Int[]

Documentation: Multi-dimensional Arrays · The Julia Language

9 Likes

By the way, this creates an anonymous function with a single argument called form_one instead of a function named form_one. To get a function named form_one, you need the syntax

function form_one()
    println("function was here")
end

instead.

5 Likes

Or Vector{Int}()

1 Like

Thank you all for your input, I appreciate it.

Array{Int}(undef, 0)

works well for me. Cheers.