Reputation: 2212
Invalidate Caches/ restart... helps me!
My code in java class is:
Intent intent = new Intent(view.getActivity(), AddPaymentActivity.class);
view.getActivity().startActivity(intent);
AddPaymentActivity has kotlin extention .kt
Got error java.lang.NoClassDefFoundError
Upvotes: 14
Views: 12787
Reputation: 51
Add Kotlin in your java project
Hope it work for u ,worked for me
Upvotes: 0
Reputation: 754
To anyone struggling inspite of all these answers, in my case, I forgot to add apply plugin: 'kotlin-android'
inside the app level's build.gradle
Upvotes: 0
Reputation: 1693
You just do it like "normally" in Java:
Intent intent = new Intent(getActivity(), KotlinActivity.class);
startActivity(intent);
Just don't forget to add Kotlin to your project fist (in the gradle files). Otherwise it won't work.
Upvotes: 3
Reputation: 61019
In my case, I forgot to add
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
and
apply plugin: 'kotlin-android'
...
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
to build.gradle
Example
project build.gradle
...
buildscript {
ext.kotlin_version = '1.1.51'
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
...
}
}
allprojects {
repositories {
jcenter()
google()
}
}
app build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
...
dependencies {
...
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
Upvotes: 9
Reputation: 33839
There is no real difference between classes produced by Java and Kotlin. If your code is statically resolved by Android Studio (as it should), then it must run unless Gradle is misconfigured.
Upvotes: 4