应用程序关闭,没有任何点击按钮的提示

时间:2018-10-20 14:45:28

标签: java android

当我单击“ 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 个答案:

答案 0 :(得分:1)

替换此行

  

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

通过以下行

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

因为您忘记添加容器参数