How to fix java.lang.IncompatibleClassChangeError?

Hi,

I meet an error when start with Kotlin. Please give me a hand. thank you.

java.lang.IncompatibleClassChangeError:
Process finished with exit code 1

Kotlin code:

import com.badlogic.gdx.backends.iosrobovm.IOSApplication
import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration
import org.robovm.apple.foundation.NSAutoreleasePool
import org.robovm.apple.uikit.UIApplication
import sample.KotlinSample

class IOSKotlinLauncher : IOSApplication.Delegate() {

protected override fun createApplication(): IOSApplication {
    val config = IOSApplicationConfiguration()
    return IOSApplication(KotlinSample(), config)
}
public fun main(argv: Array<String>) : Unit {
    val pool = NSAutoreleasePool()
    UIApplication.main<UIApplication, IOSKotlinLauncher>(argv, null, IOSKotlinLauncher::class.java)
    pool.close()
}

}

Java code:

import org.robovm.apple.foundation.NSAutoreleasePool;
import org.robovm.apple.uikit.UIApplication;

import com.badlogic.gdx.backends.iosrobovm.IOSApplication;
import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration;
import sample.KotlinSample;

public class IOSLauncher extends IOSApplication.Delegate {
@Override
protected IOSApplication createApplication() {
IOSApplicationConfiguration config = new IOSApplicationConfiguration();
return new IOSApplication(new KotlinSample(), config);
}

public static void main(String[] argv) {
    NSAutoreleasePool pool = new NSAutoreleasePool();
    UIApplication.main(argv, null, IOSLauncher.class);
    pool.close();
}

}

The main function you have in IOSKotlinLauncher is no static. You have two options there:

  1. Move it out of the class, then it will be a member of a file class
  2. wrap it into a companion object and mark as @JvmStatic:
class IOSKotlinLauncher : IOSApplication.Delegate() {

    ...

    companion object {
        @JvmStatic
        public fun main(argv: Array<String>) : Unit {
            ...
        }
    }
}

P.S. Also note that writing protected on an overridden function is redundant as well as : Unit on the main function.