gpt4 book ai didi

java.lang.IllegalArgumentException : Parameter specified as non-null is null: - android, 应用程序启动但立即崩溃

转载 作者:行者123 更新时间:2023-12-02 08:44:52 24 4
gpt4 key购买 nike

嘿伙计们,我在启动应用程序时遇到问题,我不知道问题是什么,当我启动它时它立即崩溃,从日志中我认为这是有关数据绑定(bind)的问题,但我真的不知道什么是现在错了:C

2020-04-10 22:22:22.716 32624-32624/? I/rss.ing_projec: Late-enabling -Xcheck:jni
2020-04-10 22:22:22.746 32624-32624/? E/rss.ing_projec: Unknown bits set in runtime_flags: 0x8000
2020-04-10 22:22:23.053 32624-32624/com.lswarss.ing_project I/Perf: Connecting to perf service.
2020-04-10 22:22:23.070 32624-32624/com.lswarss.ing_project V/Font: Change font:1
2020-04-10 22:22:23.071 32624-32624/com.lswarss.ing_project V/Font: Default family:android.graphics.Typeface@177a2b82
2020-04-10 22:22:23.077 32624-32676/com.lswarss.ing_project E/Perf: Fail to get file list com.lswarss.ing_project
2020-04-10 22:22:23.077 32624-32676/com.lswarss.ing_project E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2020-04-10 22:22:23.077 32624-32676/com.lswarss.ing_project E/Perf: Fail to get file list com.lswarss.ing_project
2020-04-10 22:22:23.078 32624-32676/com.lswarss.ing_project E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2020-04-10 22:22:23.156 32624-32624/com.lswarss.ing_project W/rss.ing_projec: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2020-04-10 22:22:23.157 32624-32624/com.lswarss.ing_project W/rss.ing_projec: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2020-04-10 22:22:23.213 32624-32624/com.lswarss.ing_project V/FlingOptimizerScroller: FlingOptimizerOverScroller Init
2020-04-10 22:22:23.251 32624-32624/com.lswarss.ing_project D/AndroidRuntime: Shutting down VM
2020-04-10 22:22:23.253 32624-32624/com.lswarss.ing_project E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.lswarss.ing_project, PID: 32624
java.lang.RuntimeException: Failed to call observer method
at androidx.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:226)
at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeMethodsForEvent(ClassesInfoCache.java:194)
at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeCallbacks(ClassesInfoCache.java:185)
at androidx.lifecycle.ReflectiveGenericLifecycleObserver.onStateChanged(ReflectiveGenericLifecycleObserver.java:37)
at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:361)
at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:300)
at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:339)
at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:145)
at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:131)
at androidx.fragment.app.Fragment.performStart(Fragment.java:2735)
at androidx.fragment.app.FragmentStateManager.start(FragmentStateManager.java:365)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1194)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManager.dispatchStart(FragmentManager.java:2583)
at androidx.fragment.app.Fragment.performStart(Fragment.java:2739)
at androidx.fragment.app.FragmentStateManager.start(FragmentStateManager.java:365)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1194)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManager.dispatchStart(FragmentManager.java:2583)
at androidx.fragment.app.FragmentController.dispatchStart(FragmentController.java:258)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:550)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:201)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1514)
at android.app.Activity.performStart(Activity.java:7838)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3398)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2109)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter data
at com.lswarss.ing_project.adapters.BindingAdaptersKt.bindRecyclerView(Unknown Source:7)
at com.lswarss.ing_project.databinding.PostsFragmentBindingImpl.executeBindings(PostsFragmentBindingImpl.java:125)
2020-04-10 22:22:23.253 32624-32624/com.lswarss.ing_project E/AndroidRuntime: at androidx.databinding.ViewDataBinding.executeBindingsInternal(ViewDataBinding.java:473)
at androidx.databinding.ViewDataBinding.executePendingBindings(ViewDataBinding.java:445)
at androidx.databinding.ViewDataBinding$OnStartListener.onStart(ViewDataBinding.java:1687)
at java.lang.reflect.Method.invoke(Native Method)
at androidx.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:216)
... 41 more

这是android studio给出的日志这个类有一些问题,但它有什么问题:

package com.lswarss.ing_project.adapters

import android.view.View
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import androidx.recyclerview.widget.RecyclerView
import com.lswarss.ing_project.R
import com.lswarss.ing_project.domain.PostItem
import com.lswarss.ing_project.fragments.PostsApiStatus

@BindingAdapter("listData")
fun bindRecyclerView(recyclerView: RecyclerView, data: List<PostItem>?){
val adapter = recyclerView.adapter as PostsAdapter
adapter.submitList(data)
}


@BindingAdapter("postApiStatus")
fun bindStatus(statusImageView: ImageView, status: PostsApiStatus?) {
when (status) {
PostsApiStatus.LOADING -> {
statusImageView.visibility = View.VISIBLE
statusImageView.setImageResource(R.drawable.loading_animation)
}
PostsApiStatus.ERROR -> {
statusImageView.visibility = View.VISIBLE
statusImageView.setImageResource(R.drawable.ic_connection_error)
}
PostsApiStatus.DONE -> {
statusImageView.visibility = View.GONE
}
}
}

我试图使用 udacity 类(class)中制作的应用程序来执行此应用程序火星房地产应用程序

这是我在 github 上的应用程序的链接:https://github.com/LSWarss/ing_project我遇到问题的代码位于分支 new_architecture

抱歉,如果这是一个愚蠢的问题,但我是 android 和 koltlin 的新手,甚至在堆栈上发帖:)

最佳答案

   Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter data
at com.lswarss.ing_project.adapters.BindingAdaptersKt.bindRecyclerView(Unknown Source:7

发生这种情况是因为只要我从github上看到,在您的PostsFragment中您没有将适配器设置为回收器 View ,因此当绑定(bind)适配器时它是null正在尝试访问它。

另外,我在你的主分支中注意到了这一点:

viewModel.posts.observe(viewLifecycleOwner, Observer {
posts -> recycler_view_posts.also{
it.layoutManager = LinearLayoutManager(requireContext())
it.setHasFixedSize(true)
it.adapter = PostsAdapter(posts)
}

您不必在每次观察到某些内容时都初始化回收器 View 。

在 fragment 的 onViewCreated() 方法中,您可以设置适配器和布局管理器(如果您将其添加到 PostsFragment 中,这也将解决您的错误):

private fun initRecyclerView(){
recycler_view_posts.run{
adapter = PostsAdapter(posts)
layoutManager = LinearLayoutManager(requireContext())
setHasFixedSize(true)
}
}

然后观察,您只需使用 new_architecture 分支 (adapter.submitList(list)) 的方法或通过在适配器中设置新列表并调用 adapter 来刷新内容。通知数据集更改()

关于java.lang.IllegalArgumentException : Parameter specified as non-null is null: - android, 应用程序启动但立即崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61148284/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com