1

i having a value transfered from another fragment to this fragment(mentioned below) and the data is transfered successfully but i when tried to get the data through the bundle it generates an error, and i tried but can't resolve it

help me, Thank you!

Fragment code:

public class BusinessDetail extends Fragment {

    String value1;
    Bundle bundle;
    private TextView headlineSecond;
    private TextView authorSecond;
    private TextView detailsSecond;
    private List<StringList> s;

    public BusinessDetail() {
    }

    public void receiveValue(StringList value, int positionValue) {

 bundle = new Bundle();
        bundle.putString("news", value.authorName);
        BusinessDetail detail = new BusinessDetail();
        detail.setArguments(bundle);  
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_business_detail, container, false);

        headlineSecond = (TextView) view.findViewById(R.id.id_headline_second);
        authorSecond = (TextView) view.findViewById(R.id.id_author_second);
        detailsSecond = (TextView) view.findViewById(R.id.id_details_second);


        value1 = getArguments().getString("news");
        authorSecond.setText(value1);
        return view;
    }}

Error:

          java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference
              at com.bulletin.theinvincible.bulletin.BusinessDetail.onCreateView(BusinessDetail.java:50)
              at android.support.v4.app.Fragment.performCreateView(Fragment.java:2184)
hiashutoshsingh
  • 980
  • 2
  • 14
  • 41
  • 1
    How you are using your `receiveValue()` method? because fragment object is created but not returned anywhere for fragment transaction. – Wilson Christian Apr 12 '17 at 13:33
  • i have implemented it in the mainactivity for transfering the value from fragment to another fragment .....this method is defined in the mainactivity implemented method – hiashutoshsingh Apr 12 '17 at 13:36
  • Yeah, the getArguments() is null, which probably means the receiveValue() method isn't being called on your fragment instance. – jak10h Apr 12 '17 at 14:25

0 Answers0