Kotlin 中函数“until”的未解析引用

Dro*_*hio 1 android kotlin android-gradle-plugin

我正在尝试将 Java 项目转换为 Kotlin。我收到一个非常奇怪的编译时错误,该函数直到是一个“未解决的引用”,为什么这个函数直到无法识别?

 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
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的旧 Java 方法:

 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;
        }
Run Code Online (Sandbox Code Playgroud)

小智 5

您的 Intellij IDEA 插件和您在项目中使用的 Kotlin 运行时/编译器需要匹配。您的 android studio 必须升级为支持 kotlin。检查所有这些事情并重新启动你的 android studio。