# Error:MethodError: no method matching getindex(::typeof(LCSlength), ::Int64)

**URL:** <https://discourse.julialang.org/t/error-no-method-matching-getindex-typeof-lcslength-int64/25464>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 19, 2019, 9:52pm UTC](https://discourse.julialang.org/t/error-no-method-matching-getindex-typeof-lcslength-int64/25464 "2019-06-19T21:52:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![diwas07](https://avatars.discourse-cdn.com/v4/letter/d/7bcc69/32.png) [@diwas07](https://discourse.julialang.org/u/diwas07)\
**Post date:** [June 19, 2019, 9:52pm UTC](https://discourse.julialang.org/t/error-no-method-matching-getindex-typeof-lcslength-int64/25464/1 "2019-06-19T21:52:12Z")

</div>

Hello,  
I am new to programming. I am learning Julia through online resources. I tried to implement a code in dynamic programming to find Longest common sub sequence. But I get some error, that I do not understand.  
All sorts of helps are highly appreciated.  
 ![julia1](https://global.discourse-cdn.com/julialang/original/3X/c/c/cc64274f15c9e318b2f7f99a169f40af204c3720.png)

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [June 19, 2019, 11:46pm UTC](https://discourse.julialang.org/t/error-no-method-matching-getindex-typeof-lcslength-int64/25464/2 "2019-06-19T23:46:55Z")

</div>

Welcome to discourse. Please avoid posting screenshots of your code: it will be easier for us to help you if we can copy-paste your buggy code to try and improve it.

See below for some instructions about how to correctly quote source code here:

> [@PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530):
>
> This is a short post on how to use backticks (` and ```) to quote code, so it is easy to read. This post can be linked to new users who are confused by this feature. Why By quoting your code, you get a monospaced font (which preserves indentation) and syntax highlighting. This makes it easier to read your code and help you. Displayed code looks like this: function displayed\_code(x::Int, y::Int) if x \< y println("x is smaller") else println("or not") end end Inline…

  

As for your problem, I can’t see very well (yet another problem with screenshots), but isn’t the x in your 5th line lowercase when it should be uppercase?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 20, 2019, 1:43am UTC](https://discourse.julialang.org/t/error-no-method-matching-getindex-typeof-lcslength-int64/25464/3 "2019-06-20T01:43:12Z")

</div>

Note also that your code is not correct for general Unicode (non-ASCII) strings.

1. Use `lastindex` and not `length` to get the last index in a string.

2. Use `prevind(X, a)` instead of `a-1` to get the previous index in `X`, and similarly for `b`.

---

<div class="post-metadata">

**Author:** ![fmachado](https://avatars.discourse-cdn.com/v4/letter/f/c57346/32.png) [@fmachado](https://discourse.julialang.org/u/fmachado)\
**Post date:** [June 20, 2019, 8:05am UTC](https://discourse.julialang.org/t/error-no-method-matching-getindex-typeof-lcslength-int64/25464/4 "2019-06-20T08:05:52Z")

</div>

Hey @diwas07!

It seem like you have a typo in the elseif, you probably need capitalize the x.  
Because x is not the string you are inputting (but probably some other variable in your environment), Julia doesn’t know how to access it as an array.

Another bug seems to be the final println. In the line above you probably want to assign that to a variable and then print the variable. Instead printing the function itself which doesn’t have the result you have (see below).

```julia
julia> function sum(a,b)
       return a+b
       end
sum (generic function with 1 method)
julia> sum(1,2)
3
julia> println("$sum")
sum

```

Hope this helps and good luck!
