如何使用片段中的bundle设置textview的数据?

时间:2017-04-12 13:29:57

标签: android android-fragments nullpointerexception bundle

我有一个值从另一个片段转移到这个片段(如下所述)并且数据传输成功但是当我试图通过捆绑包获取数据时它会产生错误,我试过但是无法解决它

帮助我,谢谢!

片段代码:

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;
    }}

错误:

          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)

0 个答案:

没有答案