Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 768 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Kotlin cannot access kotlin.jvm.functions.Function1 when calling kotlin function with java lambda

#1
I am trying to call the following Kotlin function from Java

override fun First(list: LinqList<ElementType>, condition: (ElementType) -> Boolean) : ElementType

like this

int first = list.First(list,(x) -> x == 5);

but i get the following error

Error java: cannot access kotlin.jvm.functions.Function1
class file for kotlin.jvm.functions.Function1 not found

I have tried googling it but i can not find the answer anywhere

Thanks in advance
Reply

#2
Method 1) Search for Function1 in your project file and rename it to First.

Method 2) Search for Function1 in your project file and remove all its occurrences.
Reply

#3
My problem got fixed when I configured Kotlin compiler and runtime for my Java module with the latest stable version (currently 1.3.30)

Just go to **Tools > Kotlin > Configure Kotlin in Project > Android with Gradle** and choose your Java module with **Single module** radio button selected then select your version and **OK**.
Reply

#4
**Another Solution:**<br>

If you have several modules in your android project, please make sure you have added the below config to every module that uses the kotlin:<br>

**Step(1)- Project build.gradle:<br>**
```
// Project build.gradle file.
buildscript {
ext.kotlin_version = '1.3.30'
...
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

```
**Step(2)- Inside each module using kotlin:<br>**
```
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

...

dependencies {
implementation "androidx.core:core-ktx:1.0.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

```
Reference:
<a href="https://developer.android.com/kotlin/add-kotlin">Add Kotlin to an existing app</a>
Reply

#5
**Android Studio:**

in my case, I have change the signature of the inner function which is making the cause of this exception. try to `clean` your project and run the app, exception will disappear
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through