I'm trying to fix an issue in an old kotlin project. But the problem is that I can't compile the code. I tried compile and run in Android Studio and IntelliJ. I got same errors.
Here are the errors:
Error:(174, 25) Expression 'length' of type 'Int' cannot be invoked as a function. The function 'invoke()' is not found
Error:(176, 60) Unresolved reference: charAt
Error:(148, 67) Expression 'size' of type 'Int' cannot be invoked as a function. The function 'invoke()' is not found
Error:(107, 76) Expression 'ordinal' of type 'Int' cannot be invoked as a function. The function 'invoke()' is not found
My gradle script:
buildscript {
ext.kotlin_version = '1.0.4'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:1.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
.
.
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
.
.
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
For ordinal error:
//enum class
enum class Category(val n:Int, val color:Int, val id : String){
HEADLINE(R.string.category_headline, Color.parseColor("#EC4A42"), "101"),
.
.
}
//where call ordinal func
intent.putExtra(MainActivity.EXTRA_CATEGORY, Category.HEADLINE.ordinal())
For charAt error:
companion object{
fun trim(s : CharSequence) : CharSequence{
var start = 0
var end = s.length()
while (start < end && Character.isWhitespace(s.charAt(start))) {
start++
}
while (end > start && Character.isWhitespace(s.charAt(end - 1))) {
end--
}
return s.subSequence(start, end)
}
}
For length():
companion object{
fun trim(s : CharSequence) : CharSequence{
var start = 0
var end = s.length()
while (start < end && Character.isWhitespace(s.charAt(start))) {
start++
}
while (end > start && Character.isWhitespace(s.charAt(end - 1))) {
end--
}
return s.subSequence(start, end)
}
}
size() usage:
class PhotoGalleryAdapter(val ac : Activity, val result : ResponseNewsDetail) : PagerAdapter(){
override fun getCount(): Int = result.gallery!!.size()
.
.
}
Any ideas/suggestions would be appreciated. Cheers!