单击按钮时应用程序关闭时没有任何提示

时间:2022-11-19 09:59:10

when i click on the "ChangeBudgetBtn" the next activity i.e. BudgetEdit does not open and the application closes without any prompt

当我点击“ChangeBudgetBtn”时,下一个活动即BudgetEdit没有打开,应用程序关闭时没有任何提示

package com.moneymgmt.moneymanagementsystem;

import android.app.Application;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

public class BudgetFragment extends Fragment {

Button ChangeBudgetBtn;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        final View rootView = inflater.inflate(R.layout.fragment_budget, container,false);

        ChangeBudgetBtn = (Button) rootView.findViewById(R.id.ChangeBudgetBtn);

        ChangeBudgetBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(v.getContext(),BudgetEdit.class));
        }
    });
    return rootView;
}
}

1 个解决方案

#1


1  

Replace this line

替换此行

final View rootView = inflater.inflate(R.layout.fragment_budget, false);

final查看rootView = inflater.inflate(R.layout.fragment_budget,false);

by the following line

通过以下行

final View rootView = inflater.inflate(R.layout.fragment_budget, container, false);

because you forgot to add the container parameter

因为你忘了添加容器参数

#1


1  

Replace this line

替换此行

final View rootView = inflater.inflate(R.layout.fragment_budget, false);

final查看rootView = inflater.inflate(R.layout.fragment_budget,false);

by the following line

通过以下行

final View rootView = inflater.inflate(R.layout.fragment_budget, container, false);

because you forgot to add the container parameter

因为你忘了添加容器参数