简体   繁体   English

尝试从 null object 参考上的字段 'android.view.View androidx.recyclerview.widget.RecyclerView$b0.a' 中读取

[英]Attempt to read from field 'android.view.View androidx.recyclerview.widget.RecyclerView$b0.a' on a null object reference

I am working on an app that does BLE scan and update recycler view.我正在开发一个执行 BLE 扫描和更新回收站视图的应用程序。 The app runs completely fine in the android studio in debug mode.该应用程序在调试模式下在 android 工作室中运行良好。 But when I release in production on the play store it crashes with the following error(from crashlytics)..但是当我在 play store 上发布生产时,它会因以下错误而崩溃(来自 crashlytics)。

Fatal Exception : java.lang.NullPointerException: Attempt to read from field 'android.view.View androidx.recyclerview.widget.RecyclerView$b0.a' on a null object reference
       at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:59)
       at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:59)
       at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3)
       at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:3)
       at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java)
       at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:2)
       at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:17)
       at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:2)
       at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:7)
       at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:2)
       at android.view.View.layout(View.java:22900)
       at android.view.ViewGroup.layout(ViewGroup.java:6389)
       at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:66)
       at android.view.View.layout(View.java:22900)
       at android.view.ViewGroup.layout(ViewGroup.java:6389)
       at androidx.coordinatorlayout.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:15)
       at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:4)
       at android.view.View.layout(View.java:22900)
       at android.view.ViewGroup.layout(ViewGroup.java:6389)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
       at android.view.View.layout(View.java:22900)
       at android.view.ViewGroup.layout(ViewGroup.java:6389)
       at androidx.appcompat.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:49)
       at android.view.View.layout(View.java:22900)
       at android.view.ViewGroup.layout(ViewGroup.java:6389)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
       at android.view.View.layout(View.java:22900)
       at android.view.ViewGroup.layout(ViewGroup.java:6389)
       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
       at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
       at android.view.View.layout(View.java:22900)
       at android.view.ViewGroup.layout(ViewGroup.java:6389)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
       at com.android.internal.policy.DecorView.onLayout(DecorView.java:831)
       at android.view.View.layout(View.java:22900)
       at android.view.ViewGroup.layout(ViewGroup.java:6389)
       at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3619)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3087)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2060)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8421)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
       at android.view.Choreographer.doCallbacks(Choreographer.java:796)
       at android.view.Choreographer.doFrame(Choreographer.java:731)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:250)
       at android.app.ActivityThread.main(ActivityThread.java:7886)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:970)

I am trying this solution But having the same issue.我正在尝试这个解决方案但有同样的问题。

Here is view holder generic class这是视图支架通用 class

  @Override
    public V onCreateViewHolder(ViewGroup parent,
                                int viewType) {. ///
        // create a new view
        View v = LayoutInflater.from(parent.getContext()).inflate(viewResId, parent, false);

        Class[] args = new Class[1];
        args[0] = View.class;

        try {
            return holderClass.getDeclaredConstructor(args).newInstance(v);
        } catch (Exception e) {
            if (e != null && e.getMessage() != null) {
                AppLogger.e(RecyclerListAdapter.class.getSimpleName(), e.getMessage());
                e.printStackTrace();
            }
            return null;
        }
    }

Any help/suggestion would be great.任何帮助/建议都会很棒。 Thanks谢谢

Answering my own question as I found its solution:在我找到解决方案时回答我自己的问题:

For me the problem was uploading.aab file to play console without specifying the proguard rules.对我来说,问题是在没有指定 proguard 规则的情况下将.aab 文件上传到游戏控制台。

you can read more about it here https://developer.android.com/studio/build/shrink-code你可以在这里阅读更多关于它https://developer.android.com/studio/build/shrink-code

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试从字段 'android.view.View androidx.recyclerview.widget.RecyclerView$ViewHolder.itemView' 读取 null object 参考 - Attempt to read from field 'android.view.View androidx.recyclerview.widget.RecyclerView$ViewHolder.itemView' on a null object reference 如何修复在 null object 参考上调用虚拟方法 'android.view.View androidx.fragment.app.FragmentActivity.findViewById(int)' 的尝试? - How to fix attempt to invoke virtual method 'android.view.View androidx.fragment.app.FragmentActivity.findViewById(int)' on a null object reference? 尝试在 null object 引用上调用虚拟方法 'void androidx.recyclerview.widget.RecyclerView.removeViewAt(int)' - Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.removeViewAt(int)' on a null object reference 遇到在 null object 参考上调用虚拟方法 'void androidx.recyclerview.widget.RecyclerView.setHasFixedSize(boolean)' 的尝试 - Encountering a Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setHasFixedSize(boolean)' on a null object reference Android:尝试在 null object 引用上调用虚拟方法“void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)” - Android:Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference 尝试在空对象引用上调用虚拟方法“void android.widget.RadioGroup.addView(android.view.View)” - Attempt to invoke virtual method 'void android.widget.RadioGroup.addView(android.view.View)' on a null object reference 尝试在空对象引用上调用虚拟方法“void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)” - Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference Attempt to invoke virtual method 'android.view.View android.widget.ImageView.findViewById(int)' on a null object reference - Attempt to invoke virtual method 'android.view.View android.widget.ImageView.findViewById(int)' on a null object reference Android ViewGroup 崩溃:尝试从空对象引用上的字段“int android.view.View.mViewFlags”读取 - Android ViewGroup crash: Attempt to read from field 'int android.view.View.mViewFlags' on a null object reference Android错误:尝试在空对象引用上调用虚拟方法……setOnClickListener(android.view.View $ OnClickListener)' - Android Error: Attempt to invoke virtual… setOnClickListener(android.view.View$OnClickListener)' on a null object reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM