我是靠谱客的博主 大方朋友,最近开发中收集的这篇文章主要介绍Attempt to read from field 'int android.view.ViewGroup$LayoutParams.width' on a null object referen,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

E/AndroidRuntime: FATAL EXCEPTION: main
Process: kodulf.swiperefreshlayoutrecyclerviewdemo, PID: 8661
java.lang.NullPointerException: Attempt to read from field 'int android.view.ViewGroup$LayoutParams.width' on a null object reference
at android.view.ViewGroup$LayoutParams.<init>(ViewGroup.java:7547)
at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:7861)
at kodulf.swiperefreshlayoutrecyclerviewdemo.MainActivity$MyAdapter.onCreateViewHolder(MainActivity.java:181)
at kodulf.swiperefreshlayoutrecyclerviewdemo.MainActivity$MyAdapter.onCreateViewHolder(MainActivity.java:161)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6794)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5975)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)

 

因为inflate的时候:

View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item, null, false);
解决办法:
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item, viewGroup, false);

最后

以上就是大方朋友为你收集整理的Attempt to read from field 'int android.view.ViewGroup$LayoutParams.width' on a null object referen的全部内容,希望文章能够帮你解决Attempt to read from field 'int android.view.ViewGroup$LayoutParams.width' on a null object referen所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部