在Kotlin中使用辅助构造函数的子类RelativeLayout

我试着在Kotlin中继承RelativeLayout,但我坚持三个构造函数。 public RelativeLayout(Context context) {} public RelativeLayout(Context context, AttributeSet attrs) {} public RelativeLayout(Context context, AttributeSet attrs, int defStyle) {} 我已经尝试了http://devnet.jetbrains.com/message/5482057中描述的过程,但是我没有看到如何将它们与我的用例相匹配。 希望三个构造函数互相调用,我尝试使用默认值,但在应用程序启动时崩溃: class SquareRelativeLayout(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) : RelativeLayout(context, attrs!!, defStyle) {} 任何暗示Kotlin的方式来做到这一点? 我正在使用Kotlin 0.8.11

Kotlin不适用于Android Studio

所有kotlin文件都无法显示在我的Android Studio上。 即使直接将java文件转换为koltin,也可以对其进行编辑,但不会出现在项目文件树中。 另外IDE建议它是一个反编译的.class文件。 我无法创建Kotlin文件。 当我这样做,它显示一个对话框说 无法创建文件/无法解析模板“Kotlin文件”错误消息:无法创建类文件 Android插件“Kotlin Extensions For Android(废弃)”无法正常安装,我可以点击安装,但是不起作用。 我的Android Studio版本2.1.2

Kotlin应用程序不显示我的JSON数组

我刚刚开始学习Kotlin,并试图用Kotlin创建我的第一个Android应用程序。 我有一个基于Restful API的web服务,它为我返回一个json数组,像下面的图像。 我的Kotlin代码通过gson库显示json数组! class MainActivity : AppCompatActivity() { val TAG:String="TipCalculatorActivity" var adapter:ArrayAdapter<Category>?=null var dsSP: MutableList<Category> = mutableListOf() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) adapter=ArrayAdapter(this,android.R.layout.simple_list_item_1,dsSP) lvCategory.adapter=adapter } override fun onResume() { super.onResume() var task=CategoryTask() task.execute() } inner class CategoryTask:AsyncTask<Void, Void, MutableList<Category>>() { override fun onPostExecute(result: MutableList<Category>?) { super.onPostExecute(result) dsSP.clear() dsSP.addAll(result!!) } override fun doInBackground(vararg […]

如何映射java.util.Optional <Something>到某些东西? 在Kotlin

我有一个方法返回java.util.Optional<Something> 。 我想从Kotlin中使用这种方法,而且我希望我的结果是Something? ,而不是Optional<Something> 如何在科特林,用惯用的方式做到这一点? 调用.orElse(null) on Optional给了我Something? 的确,但是看起来不太好。 Kotlin不会抱怨,如果我写val msg: Something = optional.orElse(null). ( msg被声明为Something ,而不是Something? – 我松散的编译类型检查)。 我使用Kotlin 1.0.3

Kotlin VerifyError:后向分支90上存在未初始化的对象

我正在使用Kotlin入门指南在IntelliJ IDEA上首次安装Kotlin,并具有以下配置: IntelliJ IDEA 2017.2.5 Build #IC-172.4343.14, built on September 26, 2017 JRE: 1.8.0_152-release-915-b12 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains sro Mac OS X 10.11.6 我使用下面的代码在一个新的Kotlin项目中创建了一个App.kt文件: fun main(args: Array<String>) { println("hello") } 通过IDE运行代码时,出现以下错误: Error:Internal error: (java.lang.VerifyError) Uninitialized object exists on backward branch 90 Exception Details: Location: org/jetbrains/kotlin/jps/build/KotlinBuilder.createCompileEnvironment(Ljava/util/Map;Lorg/jetbrains/kotlin/incremental/components/LookupTracker;Lorg/jetbrains/jps/incremental/CompileContext;Lorg/jetbrains/kotlin/jps/build/KotlinBuilder$MessageCollectorAdapter;)Lorg/jetbrains/kotlin/compilerRunner/JpsCompilerEnvironment; @171: goto Reason: Error exists in […]

Kotlin:格式字符串

我有一个回收视图,我想迭代并在每个输入字符串前添加一个项目符号点。 我有以下几点: value.strings.xml <string name="skill">• %1$s</string> ProfileListAdapter: fun bindSkills(skill: String) { itemView.recycleSkillItem.text = String.format(Locale(R.string.skill.toString()), ${R.string.skill}, skill) } 这一次打印相同的整数没有项目符号点。 在kotlin中格式化字符串的最佳做法是什么?

从Java程序中调用Kotlin编译器

有没有什么东西可以让我在内存中编译Kotlin程序,比如ECJ(Eclipse的java编译器)?

方法hashMapOf()在Kotlin中

任何人都可以给我一个hashMapOf()方法的具体例子,我应该什么时候使用它? 如果我做这样的事情: val map2 : HashMap<String, String> = hashMapOf() map2["ok"] = "yes" 这意味着我可以使用它来初始化map2属性。 但是像Kotlin中的其他方法一样: val arr = arrayListOf<String>("1", "2", "3") 有什么办法可以像上面那样使用这个方法吗?

Kotlin Android-如何实现CheckBox.OnCheckedChangeListener?

我是Kotlin新手。 我创建了一个片段,并实现了View.OnClickListener和CheckBox.OnCheckedChangeListener 。 View.OnClickListener按预期工作,但它显示CheckBox.OnCheckedChangeListener Unresloved引用。 代码如下 class LoginFragment : Fragment(), View.OnClickListener, CheckBox.OnCheckedChangeListener { override fun onClick(view: View?) { } } 我怎样才能实现CheckBox.OnCheckedChangeListener ..? 提前致谢

代码名称与Kotlin相关的一个构建错误

在尝试构建我的应用程序的iOS调试版本时,遇到以下构建错误。 我已经导入了Kotlin支持库,但实际上并没有将Kotlin代码添加到我的应用程序中。 这个错误来自哪里? Error while working with the class: java/lang/annotation/Annotation file:kotlin_Deprecated no class definition Error while working with the class: java/lang/annotation/Annotation file:kotlin_ExtensionFunctionType no class definition Error while working with the class: java/lang/annotation/Annotation file:kotlin_Metadata no class definition Error while working with the class: java/lang/annotation/Annotation file:kotlin_ReplaceWith no class definition Error while working with the class: java/lang/annotation/Annotation file:kotlin_Suppress […]