Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot access 'split': it is private in file

I develop an app with Kotlin and got this weird error today in Android Studio, so I tried the same code in InteliJ Idea as well, where I get the same behaviour. I've used the split method so far in my Android project and it worked always like a charm.

This is the code where this behaviour appears:

        val rawString = "OK;ABC;34"       
        val delimited = rawString.split(";",true,0).last()

So today, the compiler says that the split method cannot be reached, because it is private in file. Go figure!

In the code above, I'm trying to get the String "34" into my delimited variable. Are there any restrictions that I'm missing or are there any changes made on this method?

error with split method

Thanks in advance.

like image 951
BWappsAndmore Avatar asked Feb 05 '20 13:02

BWappsAndmore


1 Answers

Use like the below, split that you have used is a private function in Strings.kt class

 val rawString = "OK;ABC;34"
 val delimited = rawString.split(";", ignoreCase = true, limit = 0).last()
like image 80
MathankumarK Avatar answered Nov 06 '22 12:11

MathankumarK