getArguments()的NullPointerException .getInten(“index”,index)

时间:2013-08-20 20:45:38

标签: android

我在这段代码中看到了这个令人不快的消息

public static HelpDetailsFragment newInstance(int index) 
{
    HelpDetailsFragment detailFragment = new HelpDetailsFragment();
    Bundle bundleArgs = new Bundle();
    bundleArgs.putInt("index", index);
    detailFragment.setArguments(bundleArgs);
    return detailFragment;
}   // newInstance()

public int getCurrentIndex()
{
    return getArguments().getInt("index", 0);
}

我在这里使用此代码:

HelpDetailsFragment detailFragment = (HelpDetailsFragment) getFragmentManager()
                          .findFragmentById(R.id.helpDetailsFrame);

    if((detailFragment == null) || (detailFragment.getCurrentIndex() != index))
    {
        detailFragment = HelpDetailsFragment.newInstance(index);
        Log.i(TAG, "HelpListFragment Create and replace details fragment for item:"+index);         
        FragmentTransaction fragTrans = getFragmentManager().beginTransaction();
        fragTrans.replace(R.id.helpDetailsFrame, detailFragment);
        fragTrans.commit(); 
    }

我在这里失踪了什么?

0 个答案:

没有答案