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
One of the great wonders of Kotlin is that it's fully integrated with Java. This means that although all your application code is written Java, you can create a class in Kotlin and use it from Java without any issues. Calling Kotlin from Java code can't be easier.
Even if it's interop you can't mix Java and Kotlin in the same file. If you really want to have static methods/variables you can use an companion object . You can also access create a "real" static method in your JVM by using @JvmStatic . By using @JvmStatic you can use Java to access your Static methods like before.
To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent. # Start the activity connect to the # specified class Intent i = new Intent(this, ActivityTwo.
File -> Invalidate Caches/ restart...
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"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With