Hello, I'm android developer and I'm trying kotlin.
I have some problems and I don’t understand.
I’m trying to create android Activity in kotlin with these code:
class MyKotlinActivity(): Activity() {
public override fun onCreate(savedInstanceState : Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
val test = findViewById(R.id.test)
if (test is TextView)
test.setText(“Test complete”);
}
}
But it crashes with exception:
ERROR/AndroidRuntime(7974): FATAL EXCEPTION: main java.lang.NoSuchMethodError: android.app.Activity.onCreate at ru.demand.MyKotlinActivity.onCreate(MyKotlinActivity.kt:17) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) at android.app.ActivityThread.access$1500(ActivityThread.java:117) ...
In Java this code looks like these one:
public class MyActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); startActivity(new Intent(this,MyKotlinActivity.class)); } }
What I’m doing wrong?
P.S. I’m sorry for my English. Is it possible to speak in Russia here?