Tag: 安卓

Android室库错误:无法findsetter的字段。 (科特林)

我正在使用房间库,我有下面提到的实体: @Parcelize @Entity(tableName = “tb_option”) data class OptionsTable( var question_id: Int? = null, var option_id: Int? = null, var option: String? = null, var is_selected: Int? = null, @PrimaryKey(autoGenerate = true) var sr_no: Int = 0) : Parcelable 你可以看到我把所有的字段都声明为var但是仍然显示错误: error: Cannot find setter for field. e: e: private java.lang.Integer is_selected; e: ^ 请为此建议一些修复。 谢谢

Kotlin:如何将对象列表插入房间?

我正在试图在基本界面中定义常见的CRUD方法,如下所示: interface BaseDao { @Insert(onConflict = OnConflictStrategy.REPLACE) fun create(obj: I) @Insert(onConflict = OnConflictStrategy.REPLACE) fun createAll(objects: List) @Delete fun delete(obj: I) } Room的以下ProductDao接口从基本接口inheritance: @Dao interface ProductDao : BaseDao { // Specific methods } 当我编译fun createAll(objects: List)的定义fun createAll(objects: List)产生以下错误: 参数的types必须是用@Entity或其集合/数组注解的类。

有没有办法避免多个代码的情况下进行变异?

这是写在kotlin,但我敢肯定它在java中几乎相同。 something.setOnClickListener { availableReportRecycler.isActivated = !availableReportRecycler.isActivated if (availableReportRecycler.isActivated) availableReportRecycler.visibility = View.VISIBLE else availableReportRecycler.visibility = View.GONE } 有没有在kotlin / java的方式来简化这个代码? 我觉得它应该能够减少它像(伪代码): something.setOnClickListener { availableReportRecycler.visibility = {availableReportRecycler.isActivated = !self} ? View.VISIBLE:View.GONE } 我没有find任何相关的在线,但仍然不能得到它的工作后,强暴各种组合强迫。 你可以做得多漂亮吗? 最好的答案是获得一个虚拟的啤酒和“我没事”贴纸!

Android Anko警报与自定义视图错误(Kotlin)

我想创建一个使用anko自定义元素的警告对话框。 我find的每个指南和教程都使用这种方法: alert { customView { textView(“Hello”) } }.show() 但是我在customView出现错误: Error:(73, 13) Type inference failed: Not enough information to infer parameter T in inline fun Activity.customView(theme: Int = …, init: T.() -> Unit): T Please specify it explicitly. Anko有什么变化,而且没有记录?

Android Studio 3.0未解决的参考:SupportedLanguages for AIConfiguration类在Dialogflow(api.ai)

我正在通过查询Dialogflow代理程序在Kotlin中构建一个chatbot Android应用程序。 我正在使用Dialogflow Android客户端github存储库自述文件和该存储库中提供的示例应用程序作为构建应用程序的基础。 如上所述, AIConfiguration.SupportedLanguages java代码AIConfiguration.SupportedLanguages工作: import ai.api.android.AIConfiguration; ….. private void initService(final LanguageConfig selectedLanguage) { final AIConfiguration.SupportedLanguages lang = AIConfiguration.SupportedLanguages.fromLanguageTag(selectedLanguage.getLanguageCode()); ….. 你可以在这里find完整的用法。 当我在Kotlin中实现时: import ai.api.android.AIConfiguration …. private fun initService() { //final AIConfiguration.SupportedLanguages lang = AIConfiguration.SupportedLanguages.fromLanguageTag(selectedLanguage.getLanguageCode()); val config = AIConfiguration(CLIENT_ACCESS_TOKEN, AIConfiguration.SupportedLanguages.EnglishGB, AIConfiguration.RecognitionEngine.System) …. 在Android 3.0中,我得到了ALConfiguration.SupportedLanguages的“ Unresolved reference:SupportedLanguages ”的AIConfiguration.SupportedLanguages 。 AIConfiguration.RecognitionEngine解决得很好。 为什么这个问题会发生? 我可以实施哪些解决方案/解决方案? 我的更高级别的build.gradle文件: apply plugin: […]

无法获得Room DB与Kotlin一起运行

你可以在我的回购中find所有的代码: https : //github.com/NWuensche/BookNotes/tree/add-room-db 我得到以下错误: E/AndroidRuntime: FATAL EXCEPTION: main Process: com.nwuensche.booknotes, PID: 22753 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nwuensche.booknotes/com.nwuensche.booknotes.MainActivity}: java.lang.RuntimeException: cannot find implementation for com.nwuensche.booknotes.model.AppDatabase. AppDatabase_Impl does not exist at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2684) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2751) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1496) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6186) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) Caused by: java.lang.RuntimeException: cannot find […]

如何为Kotlin和Android设置Mockito

我想使用Mockito进行unit testing,所以我将Mockito库添加到我的gradle依赖项中。 testImplementation ‘junit:junit:4.12’ testCompile ‘org.mockito:mockito-core:2.12.0’ 但是,我仍然不能使用任何Mockito注释。 /androidTest/ExampleTest.kt @RunWith(MockitoJUnitRunner::class) // Unresolved reference MockitoJUnitRunner @Mock // Unresolved reference Mock 我错过了什么?

Handler的post在Kotlin里是不行的,怎么了?

有人可以告诉我什么是错的,我尝试使用一个Handler发布一个Runnable但它不是执行 var mHandler: Handler? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) mHandler = Handler() var runnable = Runnable { Log.d(“TEST”, “++++ runable”) Log.d(“TEST”, “++++ come end”) } Log.d(“TEST”, “++++ runnable” + runnable) Log.d(“TEST”, “++++ handle” + mHandler) mHandler!!.post { runnable } } 这是输出 09-21 00:56:04.067 4419-4419 /? D / TEST:++++ runnablecom.vpioneer.activity.MainActivity$onCreate$runnable$1@529b8fb4 09-21 00:56:04.067 […]

如何在init块kotlin中得到exception

下面的代码,在init函数中我创建一个Person对象,并有一个exception,现在我想停止像java返回catch的进度。 我该怎么做? class Person { val age: String = “10” private lateinit var person: Person init { try { person = get(2) } catch (exception: Throwable) { } println(“—————-do it $person.age”) } fun get(i: Int): Person { when (i) { 1 -> { return Person() } else -> { throw MyException(“aaaaaaaaa”) } } } }

函数在kotlin返回值结束之前Fuel.post

我有一个Fuel.post函数,返回Fuel.post结束前的值,这是代码… var res = rs.requestLogin(“user”, “password”) 和我的function fun requestLogin(user : String, pass : String) : String { var res = “” val _params = HashMap() _params.put(“user”, user) _params.put(“pass”, pass) Fuel.post(Constantes.ENDPOINT_LOGIN, _params.toList()) .responseString(Charset.forName(“UTF8”)){ request, response, result -> when (result) { is Result.Success -> { res = “0” } is Result.Failure ->{ res = “-1” } } […]