未解决的参考:kotlinx [英] Unresolved reference: kotlinx

查看:199
本文介绍了未解决的参考:kotlinx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Android Studio中试用Kotlin和Kotlin Android扩展.我已经在Ubuntu 14.04上的Android Studio v 1.5.1和OS X El Capitan上的Android Studio v 1.5.1中都尝试了此方法,

I am trying to try out Kotlin and the Kotlin Android extensions in Android Studio. I have tried this both in Android Studio v 1.5.1 on Ubuntu 14.04, and in Android Studio v 1.5.1 on OS X El Capitan with the same result.

这是我在做什么:

  1. 我安装了Kotlin插件1.0.0-beta-35950-IJ141-11
  2. 创建一个新的空白Android项目
  3. 将MainActivity文件转换为Kotlin(通过help-> findaction->将文件转换为kotlin)
  4. 为Kotlin配置项目

然后我进入生成的content_main.xml文件,并为"Hello World!"添加一个ID(Hello). TextView.

I then go into the generated content_main.xml file and add an id (hello) for the "Hello World!" TextView.

<?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>  

然后在转换后的MainActivity中添加一行以设置TextView. (如下所示). 然后,Android Studio提示我(通过alt输入)插入此行(也如下所示)

Then in the converted MainActivity I add a line to set the TextView. (shown below). Android Studio then prompts me (via alt-enter) to insert this line (also shown below)

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

因此,此时一切似乎很好

但是当我尝试编译它时,我得到了

but then when I try to compile this I get

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

请注意,我没有安装Kotlin Android扩展插件.从几天前开始,现在应该将其包含在主插件中,并标记为已过时. (实际上,如果您尝试在具有最新插件的情况下进行安装,则不会安装任何新东西)

Notice that I did not install the Kotlin Android extensions plugin. As of a couple of days ago this is now supposed to be included in the main plug in and is marked as obsolete. (In fact if you try to install it when you have the latest plugin, nothing new is installed)

有人看到我在做什么错吗?

Anyone see what I am doing wrong?

MainActivity

MainActivity

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)
    }
}

推荐答案

在构建脚本的依赖项中添加kotlin-android-extensions:

Add kotlin-android-extensions in our buildscript's dependencies:

1.在您的项目级别build.gradle

buildscript {
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
    }
}

并应用kotlin-android-extensions插件:

2.在您的模块级build.gradle

apply plugin: 'kotlin-android-extensions'


原始答案:

很有可能是Kotlin插件中的错误.我已经在其跟踪器上提交了问题.

Most likely it's a bug in the Kotlin plugin. I've filed an issue on their tracker.

这篇关于未解决的参考:kotlinx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆