小编kok*_*yaa的帖子

java.lang.IllegalStateException:TextView不能为null(Android/Kotlin)

我的Recycler View有以下ViewHolder类,

inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        private val dateText = itemView.itemDateSummaryList
        private val systolicVal = itemView.systolicValue
        private val diastolicVal = itemView.diastolicValue

        fun update(listItem: SummaryListItemModel) {
            Log.i(TAG, "Update method called " + listItem.date)
            dateText.text = listItem.date
            systolicVal.text = listItem.sysVal.toInt().toString()
            diastolicVal.text = listItem.diasVal.toInt().toString()
        }

    }
Run Code Online (Sandbox Code Playgroud)

但是,当我运行该应用程序时,该dateText.text = listItem.date说法出现错误,

java.lang.IllegalStateException: dateText must not be null
at *****.******.*****.ui.detailview.bloodpressure.SummaryListAdapter$ItemViewHolder.update(SummaryListAdapter.kt:68)
Run Code Online (Sandbox Code Playgroud)

但是listItem.date不是null我已经检查了Log.

android kotlin recycler-adapter android-recyclerview

12
推荐指数
2
解决办法
1万
查看次数

java.lang.NoSuchMethodError:org.junit.platform.launcher.Launcher.execute

我正在尝试运行以下示例单元测试用例

class ExampleUnitTest {

    @Test
    fun addition_is_Correct() {
        assertEquals(4, (2 + 2).toLong())
    }

}
Run Code Online (Sandbox Code Playgroud)

但我得到以下异常

Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute(Lorg/junit/platform/launcher/LauncherDiscoveryRequest;)V
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:61)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Run Code Online (Sandbox Code Playgroud)

即使我已经更新了所有的Junit依赖build.gradle文件,如下所示

testImplementation 'junit:junit:4.12'
testImplementation 'org.jetbrains.spek:spek-api:1.1.5'
testImplementation 'org.jetbrains.spek:spek-junit-platform-engine:1.1.5'
testImplementation 'org.junit.platform:junit-platform-launcher:1.0.0'
testImplementation 'org.junit.platform:junit-platform-runner:1.0.0'
testImplementation 'org.junit.vintage:junit-vintage-engine:4.12.3'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.0.0'
Run Code Online (Sandbox Code Playgroud)

有什么解决办法吗?

junit android unit-testing android-studio junit-jupiter

6
推荐指数
1
解决办法
4349
查看次数

将对象列表传递给片段

class CholesterolPagingFragment: Fragment() {

    companion object {
        fun newInstance(): CholesterolPagingFragment {
            val args = Bundle()
            val fragment = CholesterolPagingFragment()
            fragment.arguments = args
            return fragment
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val view = inflater.inflate(R.layout.fragment_paging_cholesterol, container, false)

        return view
    }

}
Run Code Online (Sandbox Code Playgroud)

我在Kotlin中编写了上面的代码来初始化一个片段.虽然我无法找到将对象列表(例如:)传递List<Human>给此片段的方法.我试过Bundle()但却找不到合适的方法.

android android-fragments kotlin android-bundle

4
推荐指数
1
解决办法
7004
查看次数

无法在写事务(Realm + Android)之外修改托管对象

我已经实现了以下UserProfile从领域数据库更新的方法。

override fun updateCurrentUser(userProfile: UserProfile, successAction: () -> Unit) {
        val realm = Realm.getDefaultInstance()
        realm.executeTransactionAsync(
                object : Realm.Transaction {
                    override fun execute(realm: Realm) {

                        val user = realm.where(UserProfile::class.java).equalTo("userName", userProfile.userName).findFirst()
                        user?.firstName = userProfile.firstName
                        user?.lastName = userProfile.lastName
                        user?.gender = userProfile.gender
                        user?.height = userProfile.height
                        user?.weight = userProfile.weight
                        user?.dob = userProfile.dob
                        user?.firstTimeSetupDone = true

                    }
                },
                object : Realm.Transaction.OnSuccess {
                    override fun onSuccess() {
                        Log.i(TAG, "Saved User successfully with $userProfile")
                        successAction()
                    }

                },
                object : Realm.Transaction.OnError {
                    override fun onError(error: Throwable?) { …
Run Code Online (Sandbox Code Playgroud)

android realm kotlin realm-mobile-platform

2
推荐指数
1
解决办法
3970
查看次数