片段活动和列表适配器空指针异常错误

时间:2015-11-09 21:30:51

标签: android-activity fragment listadapter

我创建了listview和片段活动。但是List List Adapter无法正常工作。 片段代码:

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

    Intent intent = new Intent(getActivity(), MainFeed.class);
    getActivity().startActivity(intent);
    // Inflate the layout for this fragment
    return rootView;
}

活动代码:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_feed);

    listView = (ListView) findViewById(R.id.list);

    feedItems = new ArrayList<FeedItem>();

    listAdapter = new FeedListAdapter(this, feedItems);

列出适配器代码:

public FeedListAdapter(Activity activity, List<FeedItem> feedItems) {
    this.activity = activity;
    this.feedItems = feedItems;
}

列表适配器为空。

请帮帮我。

1 个答案:

答案 0 :(得分:0)

尝试为FeedListAdapter(上下文cntx,List feedItems)更改FeedListAdapter(活动活动,列出feedItems)我认为您正在发送上下文并尝试在构造函数中获取活动...