qq_44681001 2019-07-27 14:06 采纳率: 0%
浏览 351

求助!!!Fragment 里 添加一个Fragment 实现跳转出现空指针问题

```java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference



 @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mBtnout = view.findViewById(R.id.btn_out);
        mTextgroup = view.findViewById(R.id.text_group);
        //设置适配器
        listView = view.findViewById(R.id.list_item1);
        listView.setAdapter(new GroupAdapter(getActivity()));

        mBtnattend = view.findViewById(R.id.btn_attend);
        mBtnattend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getFragmentManager().beginTransaction().replace(R.id.list_item1,partcipateFragment).commitAllowingStateLoss();
            }
        });




然后这个是布局文件

<?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="match_parent"
    android:orientation="vertical">

    <RelativeLayout
        android:padding="15dp"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:background="#E8CA88">

        <Button
            android:id="@+id/btn_out"
            android:layout_marginLeft="15dp"
            android:layout_marginTop="13dp"
            android:layout_width="15dp"
            android:layout_height="15dp"
            android:background="@drawable/fanhui"/>

        <TextView
            android:id="@+id/text_group"
            android:layout_marginTop="7dp"
            android:layout_centerHorizontal="true"
            android:textSize="20sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="xxx"/>



    </RelativeLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:orientation="horizontal">

        <Button
            android:id="@+id/btn_group"
            android:layout_width="400dp"
            android:layout_height="40dp"
            android:text="xxx"
            android:layout_weight="1"
            android:background="#fff"/>

        <Button
            android:id="@+id/btn_attend"
            android:layout_weight="1"
            android:layout_width="400dp"
            android:layout_height="40dp"
            android:text="xxx"
            android:background="#fff"/>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/li_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    <ListView
        android:id="@+id/list_item1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"></ListView>
    </LinearLayout>

</LinearLayout>

  • 写回答

2条回答 默认 最新

  • 代码的灵魂是bug! 2019-07-27 18:14
    关注

    partcipateFragment这个东西初始化了没

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题