Android FragmentManager BackStackRecord.run throwing NullPointerException
2016-04-29 11:44
501 查看
在使用DialogFragment的时候,有时候总是报出
这个错误,然后自己去找这个问题。但是很多情况并非是FragmentManager的错误,而是有里面的View引起的。
比如在DialogFragment中使用WheelView的时候,出现过问题。
https://github.com/wangjiegulu/WheelView
想要实现如下效果:
开始的时候设置这个布局如下,一直出现问题:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="20dp"
android:gravity="center"
android:padding="10dp"
android:text="关闭"
android:textColor="@color/black"
android:textSize="18sp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"></View>
<TextView
android:id="@+id/sure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="20dp"
android:gravity="center"
android:padding="10dp"
android:text="确认"
android:textColor="@color/black"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.robot.tongbanjie.widget.WheelView
android:id="@+id/wheel_view_main"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<com.robot.tongbanjie.widget.WheelView
android:id="@+id/wheel_view_decimal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
解决方法,固定WheelView的宽度:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="20dp"
android:gravity="center"
android:padding="10dp"
android:text="关闭"
android:textColor="@color/black"
android:textSize="18sp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"></View>
<TextView
android:id="@+id/sure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="20dp"
android:gravity="center"
android:padding="10dp"
android:text="确认"
android:textColor="@color/black"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<com.robot.tongbanjie.widget.WheelView
android:id="@+id/wheel_view_main"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp" />
<com.robot.tongbanjie.widget.WheelView
android:id="@+id/wheel_view_decimal"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
总结:
(1)报出Android FragmentManager BackStackRecord.run throwing NullPointerException错误,是由于里面的WheelView引起的。
(2)WheelView有时候需要设置固定的宽度,才可以。
Android
FragmentManager BackStackRecord.run throwing NullPointerException
这个错误,然后自己去找这个问题。但是很多情况并非是FragmentManager的错误,而是有里面的View引起的。比如在DialogFragment中使用WheelView的时候,出现过问题。
https://github.com/wangjiegulu/WheelView
想要实现如下效果:
开始的时候设置这个布局如下,一直出现问题:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="20dp"
android:gravity="center"
android:padding="10dp"
android:text="关闭"
android:textColor="@color/black"
android:textSize="18sp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"></View>
<TextView
android:id="@+id/sure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="20dp"
android:gravity="center"
android:padding="10dp"
android:text="确认"
android:textColor="@color/black"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.robot.tongbanjie.widget.WheelView
android:id="@+id/wheel_view_main"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<com.robot.tongbanjie.widget.WheelView
android:id="@+id/wheel_view_decimal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
解决方法,固定WheelView的宽度:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="20dp"
android:gravity="center"
android:padding="10dp"
android:text="关闭"
android:textColor="@color/black"
android:textSize="18sp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"></View>
<TextView
android:id="@+id/sure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="20dp"
android:gravity="center"
android:padding="10dp"
android:text="确认"
android:textColor="@color/black"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<com.robot.tongbanjie.widget.WheelView
android:id="@+id/wheel_view_main"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp" />
<com.robot.tongbanjie.widget.WheelView
android:id="@+id/wheel_view_decimal"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
总结:
(1)报出Android FragmentManager BackStackRecord.run throwing NullPointerException错误,是由于里面的WheelView引起的。
(2)WheelView有时候需要设置固定的宽度,才可以。
相关文章推荐
- Android实现 UDP
- Android实现RecyclerView自定义列表、点击事件以及下拉刷新
- android listview需要呈现多个布局
- Android中解决EditText放到popupWindow中,原有复制、粘贴、全选、选择功能失效问题
- android viewPager 滑动标题颜色渐变效果
- android 获取文件路径(内置sd卡和外置sd卡)。
- Android Animation
- 反射还能这么玩?
- Android录制屏幕在转出gif
- weakreference handler android莫须有的罪名
- Android 如何获取在strings里面设置的值
- AidlTokenType.import or android:layout_height="match_parent"
- Android涉及到的设计模式
- android中关于上下文菜单ContextMenu数据值的转递
- android 蓝牙设备监听广播
- Android应用的界面编程(三)--TextView及其子类
- Android 代码混淆异常 transformClassesAndResourcesWithProguardForRelease FAILED
- Android获取SharedPreferences失败,且App无法启动
- Android framework修改----关屏动画效果
- 关于AnsycTask你需要知道的几个问题