1

I am trying to convert a Java project to Kotlin. I get a really strange compile time error the function until is an "Unsolved Reference", how come this function until is not recognized?

 fun renderChildrenToRight(canvas: Canvas, startIndex: Int, stopIndex: Int) {
    val itemRight = nodePosition!!.x + nodeRectLimits.right
    val itemExternalPaddingWidth = getRenderAttribute(AttributeExternalPaddingWidth, AttributeDefaultExternalPadding)
    val itemTop = nodePosition!!.y + nodeRectLimits.top
    val itemExternalPaddingHeight = getRenderAttribute(AttributeExternalPaddingHeight, AttributeDefaultExternalPadding)
    val childItemsSize = getChildItemsSize(startIndex, stopIndex)
    var nextItemTop = itemTop + childItemsSize / 2
    val x = itemRight + itemExternalPaddingWidth


    for (i in startIndex until stopIndex) {
        val currentNode = _children[i]
        val bulletDesiredHeight = currentNode.desiredHeightWithChildren
        val y = nextItemTop - bulletDesiredHeight / 2
        currentNode.setNodePosition(x, y)


        currentNode.renderWithChildren(canvas, BulletRenderStyle.ToTheRight)
        nextItemTop -= bulletDesiredHeight + itemExternalPaddingHeight
    }
}

This is my old Java method:

 public void renderChildrenToRight(Canvas canvas, int startIndex, int stopIndex) {
        int itemRight = getNodePosition().x + getNodeRectLimits().right;
        int itemExternalPaddingWidth = getRenderAttribute(AttributeExternalPaddingWidth, AttributeDefaultExternalPadding);
        int itemTop = getNodePosition().y + getNodeRectLimits().top;
        int itemExternalPaddingHeight = getRenderAttribute(AttributeExternalPaddingHeight, AttributeDefaultExternalPadding);
        int childItemsSize = getChildItemsSize(startIndex, stopIndex);
        int nextItemTop = itemTop + childItemsSize / 2;
        int x = itemRight + itemExternalPaddingWidth;


        for (int i = startIndex; i < stopIndex; i++) {
            Node currentNode = _children.get(i);
            int bulletDesiredHeight = currentNode.getDesiredHeightWithChildren();
            int y = nextItemTop - bulletDesiredHeight / 2;
            currentNode.setNodePosition(x, y);


            currentNode.renderWithChildren(canvas, BulletRenderStyle.ToTheRight);
            nextItemTop -= bulletDesiredHeight + itemExternalPaddingHeight;
        }
sourav.bh
  • 467
  • 1
  • 7
  • 20
Drocchio
  • 383
  • 4
  • 21
  • Similar question: https://stackoverflow.com/questions/31712046/kotlin-unresolved-reference-in-intellij – Randy Jan 01 '19 at 02:25
  • 2
    until is a function in Kotlin's stdlib, not a keyword. Do you have the stdlib on your classpath? – Egor Jan 01 '19 at 02:49
  • well actually there is a similar question, and also the reply I received basically says what was in the original response. Should we mark it as duplicate? Should I accept the answer or not? Thank you to let me know that `until`is a function and not a keyword, interesting. Problem solved anyway. – Drocchio Jan 01 '19 at 12:19
  • Possible duplicate of [Kotlin unresolved reference in IntelliJ](https://stackoverflow.com/questions/31712046/kotlin-unresolved-reference-in-intellij) – leonardkraemer Sep 19 '19 at 05:40
  • @Drocchio you can accept an answer if you want, it might help s.o. who stumbles across your question. I will vote to close it as duplicate though, because it makes the link to the site with more answers more visible. – leonardkraemer Sep 19 '19 at 05:42
  • ok @leonardkraemer I am going to accept one answer or the duplicate – Drocchio Sep 20 '19 at 20:08

4 Answers4

5

Your Intellij IDEA plugin and the Kotlin runtime/compiler that you use in the project need to match.Your android studio must be upgraded with kotlin support. Check all these things and restart your android studio.

Niyati Mehta
  • 102
  • 5
3

The answer from @Niyati Mehta is right. The issue is caused by project vs IDE kotlin plugin versions mismatching, but I think I should add a bit more:

The only way I could get the IDE to acknowledge this (You should get a yellow warning on your gradle file) was reinstalling the whole IDE, since apparently updating it version 3.4 to 3.5 messed something up (I also removed .android and .android-studio folders, not sure if also needed). Only then I got the warning on the gradle file of the project.

Once I got it, I looked up and updated the IDE version to match project by doing this: Tools -> Kotlin -> Configure Kotlin Plugin Updates -> Check for updates now (Source)

Hope this can help somebody else too.

DuckN'Bear
  • 365
  • 1
  • 4
  • 19
1

I specifically had this issue with the latest version of Kotlin at the time: 1.3.61

I downgraded my code to 1.3.60, and the issue went away. Maybe the release isn't as stable as it should be! I still kept my IDE at 1.3.61, and it gives me the warning in my build.gradle file that they aren't the same version, but the warnings have gone away. Hopefully Google will fix the issue in the next version soon.

ConcernedHobbit
  • 764
  • 1
  • 8
  • 17
0

File -> Invalidate Cashes / Restart -> Invalidate and Restart

Njuacha Hubert
  • 388
  • 3
  • 14