# UndefRefError: access to undefined reference, how to fix the following error?

**URL:** https://discourse.julialang.org/t/undefreferror-access-to-undefined-reference-how-to-fix-the-following-error/28213
**Category:** General Usage
**Created:** [August 30, 2019, 3:09pm UTC](https://discourse.julialang.org/t/undefreferror-access-to-undefined-reference-how-to-fix-the-following-error/28213 "2019-08-30T15:09:19Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)
#### Post date: [August 30, 2019, 3:09pm UTC](https://discourse.julialang.org/t/undefreferror-access-to-undefined-reference-how-to-fix-the-following-error/28213/1 "2019-08-30T15:09:20Z")

</div>

I’m running some Julia code and the error message I get is as the following:

```julia
UndefRefError: access to undefined reference
   in top-level scope at base/None
   in simulate! at do_sim.jl:10
   #simulate!#46 at so_sim.jl:38
   simulateNextEvent! at do_sim.jl:84
   simulateEvent! at do_sim.jl:184
   findAmbToCallReturnRouteDistTime! at decisions.jl:117
   get property at base/sysing.jl:18

```

Yet, I have checked the code several times and it should be good. Any comments about where and how to fix the error here?

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [August 30, 2019, 3:12pm UTC](https://discourse.julialang.org/t/undefreferror-access-to-undefined-reference-how-to-fix-the-following-error/28213/2 "2019-08-30T15:12:31Z")

</div>

Here’s one way that such an error can get thrown:

```nohighlight
julia> r = Ref{Any}()
Base.RefValue{Any}(#undef)

julia> r[]
ERROR: UndefRefError: access to undefined reference

```

Somewhere in your code you’re trying to access a reference that was initialized as undef and never set. Impossible to say more without the code itself.

---

<div class="post-metadata">

### Author: ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)
#### Post date: [August 30, 2019, 3:22pm UTC](https://discourse.julialang.org/t/undefreferror-access-to-undefined-reference-how-to-fix-the-following-error/28213/3 "2019-08-30T15:22:05Z")

</div>

What is `Ref` by the way?

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [August 30, 2019, 3:25pm UTC](https://discourse.julialang.org/t/undefreferror-access-to-undefined-reference-how-to-fix-the-following-error/28213/4 "2019-08-30T15:25:33Z")

</div>

It’s just a box that can hold something — and what it is holding onto can change.

[https://docs.julialang.org/en/v1/base/c/#Core.Ref](https://docs.julialang.org/en/v1/base/c/#Core.Ref)
