Nicht aufgelöste Referenz: kotlinx

Ich versuche, Kotlin und die Kotlin-Android-Erweiterungen in Android Studio auszuprobieren. Ich habe dies sowohl in Android Studio 1.5.1 unter Ubuntu 14.04 als auch in Android Studio 1.5.1 unter OS X El Capitan mit demselben Ergebnis versucht.

Hier ist was ich tue:

Ich installiere das Kotlin-Plugin 1.0.0-beta-35950-IJ141-11Erstelle ein neues leeres Android ProjektKonvertieren Sie die MainActivity-Datei in Kotlin (über help-> findaction-> convert file to kotlin)Konfiguriere das Projekt für Kotlin

Ich gehe dann in die generierte content_main.xml-Datei und füge eine ID (Hallo) für die "Hallo Welt!" Textvorschau

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.gmail.npnster.mykotlinfirstproject.MainActivity"
    tools:showIn="@layout/activity_main">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:id="@+id/hello"
        />
</RelativeLayout>  

Dann füge ich in der konvertierten MainActivity eine Zeile hinzu, um die TextView einzustellen. (siehe unten). Android Studio fordert mich dann auf (per Alt-Enter), diese Zeile einzufügen (siehe auch unten)

import kotlinx.android.synthetic.main.content_main.*

So an diesem Punkt alles scheint fine

Aber wenn ich dann versuche, dies zu kompilieren, erhalte ich

Unresolved reference: kotlinx
Unresolved reference: kotlinx
Unresolved reference: hello

Hinweis, dass ichnich Installieren Sie das Kotlin Android Extensions Plugin. Ab vor ein paar Tagen soll dies nun im Hauptplugin enthalten sein und wird als veraltet markiert. (In der Tat, wenn Sie versuchen, es zu installieren, wenn Sie das neueste Plugin haben, wird nichts Neues installiert)

Weiß jemand was ich falsch mache?

Hauptaktivitä

import android.os.Bundle
import android.support.design.widget.FloatingActionButton
import android.support.design.widget.Snackbar
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.View
import android.view.Menu
import android.view.MenuItem
import kotlinx.android.synthetic.main.content_main.*


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val toolbar = findViewById(R.id.toolbar) as Toolbar
        setSupportActionBar(toolbar)
        print("setting text view value to hey")
        hello.text = "hey"

        val fab = findViewById(R.id.fab) as FloatingActionButton
        fab.setOnClickListener { view -> Snackbar.make(view, "Replace this with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show() }
    }

    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        // Inflate the menu; this adds items to the action bar if it is present.
        menuInflater.inflate(R.menu.menu_main, menu)
        return true
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        val id = item.itemId

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true
        }

        return super.onOptionsItemSelected(item)
    }
}

Antworten auf die Frage(16)

Ihre Antwort auf die Frage