滚动NullPointerException
时得到RecyclerView
,但我不明白该空错误在哪里。 RecyclerView
也没有显示。为什么以及在哪里出现此错误。我也试过不
使用图像,因为我认为这与图像分辨率有关,但仍然崩溃。请帮忙。
这是我的错误堆栈跟踪:
FATAL EXCEPTION: main
Process: com.mqa.android.moviereview, PID: 11474
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.view.View.canScrollVertically(int)' on a null object reference
at android.support.v4.widget.SwipeRefreshLayout.canChildScrollUp(SwipeRefreshLayout.java:678)
at android.support.v4.widget.SwipeRefreshLayout.onInterceptTouchEvent(SwipeRefreshLayout.java:701)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2504)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2963)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2593)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2963)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2593)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2963)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2593)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2963)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2593)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2963)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2593)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2963)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2593)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2963)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2593)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2963)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2593)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:448)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1828)
at android.app.Activity.dispatchTouchEvent(Activity.java:3346)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:410)
at android.view.View.dispatchPointerEvent(View.java:11975)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4836)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4647)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4183)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4236)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4202)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4329)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4210)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4386)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4183)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4236)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4202)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4210)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4183)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6743)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6717)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6678)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6849)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:249)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:325)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:6698)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
这是我的一些代码
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
val spinnerItems = resources.getStringArray(R.array.genre)
val spinnerAdapter = ArrayAdapter(context,
android.R.layout.simple_spinner_dropdown_item,
spinnerItems)
genreSpn?.adapter = spinnerAdapter
adapter = ReviewAdapter(requireContext(),reviews) {
context?.startActivity<DetailReviewActivity>("id" to "${it.reviewId}")
}
genreRV.adapter = adapter
val request = ApiRepository()
val gson = Gson()
presenter = HomePresenter(this, request, gson)
genreSpn.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
genre = genreSpn.selectedItem.toString()
print(genre)
presenter.getReviewList(genre)
}
override fun onNothingSelected(parent: AdapterView<*>) {}
}
homeSwipe.onRefresh {
presenter.getReviewList(genre)
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_home, container, false)
}