java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.mcc.wpnews.adapters.MenuCommonAdapter$ViewHolder.<init>(MenuCommonAdapter.java:67)
at com.mcc.wpnews.adapters.MenuCommonAdapter.onCreateViewHolder(MenuCommonAdapter.java:47)
at com.mcc.wpnews.adapters.MenuCommonAdapter.onCreateViewHolder(MenuCommonAdapter.java:27)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6493)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5680)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5563)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5559)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2229)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1556)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1516)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:608)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3693)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3109)
at android.view.View.measure(View.java:19886)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6085)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19886)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1306)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.widget.ScrollView.onMeasure(ScrollView.java:348)
at android.view.View.measure(View.java:19886)
at android.support.v4.widget.SwipeRefreshLayout.onMeasure(SwipeRefreshLayout.java:626)
at android.view.View.measure(View.java:19886)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6085)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19886)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:19886)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6085)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19886)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1060)
at android.view.View.measure(View.java:19886)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6085)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
at android.view.View.measure(View.java:19886)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6085)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19886)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6085)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:19886)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6085)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19886)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6085)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:693)
at android.view.View.measure(View.java:19886)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2319)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1410)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1663)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1298)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6437)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:876)
at android.view.Choreographer.doCallbacks(Choreographer.java:688)
at android.view.Choreographer.doFrame(Choreographer.java:623)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:862)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6238)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
答案 0 :(得分:0)
首先,您必须了解什么是NullPointer异常。让我解释得尽可能简单。
空指针异常: 当您在尚未初始化的变量(视图)上调用方法或函数时,将引发此异常。
在这里,您收到此错误,因为您可能尚未声明并将视图正确映射到变量名。
您必须做什么? 只需检查您是否已声明视图。在这里,您遇到了OnClick侦听器错误。因此,我认为它是按钮。因此,请检查该按钮是否存在于xml布局中,以及您是否已在Java代码中正确声明和初始化了此
。