0

I have a Kotlin class with a method, which creates some text and then I want to write it to a file:

import java.io.File
import java.util.*
import kotlin.io.*

class MyClass {
    fun run() {
        val result = html {
            head {
                title { +"Entry page" }
            }
            body {
                h1 {
                    +"Map"
                }
                +"Some HTML code"
            }
        }
        File("target/wdef/index.html").writeText(result)
    }
}

I get an error - the writeText(result) is highlighted red and I get the error message Error:(26, 40) Kotlin: Unresolved reference: writeText.

How can I fix it?

Glory to Russia
  • 17,289
  • 56
  • 182
  • 325
  • Looks like a problem with build \ project configuration. Can you build it from CLI? Please answer here – voddan Feb 26 '16 at 09:50

1 Answers1

3

A problem might be that you pass a wrong type to writeText. It requires String, but you pass an html building object HTML. Try to convert it with toString:

File("target/wdef/index.html").writeText(result.toString())
voddan
  • 31,956
  • 8
  • 77
  • 87