transfer List from activity to fragment in Android

Hello,
I have an activity:



public List<Steps> steps;
Recipe recipe;
@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail_activity);
///..........
steps = recipe.getRecipeSteps();

int len1 = steps.size();
Log.i(TAG, "Steps length=" + len1);

}
public List<Steps> getMyData() {
return steps;
}



and a fragment



public class FragmentStepTitle extends Fragment {
// Whether the app has two panel( tablet ) or one panel( phone ).
//private boolean hasTwoPanel = false;

@
@
public View onCreateView(LayoutInflater inflater, @ ViewGroup container, @ Bundle savedInstanceState) {
.....
//receive info from detail

DetailActivity activity = (DetailActivity) getActivity();
List<Steps> myDataFromActivity = activity.getMyData();
Log.i("Fragment",myDataFromActivity.get(0).getShor tDescription());


return ret;
}
}



The error caused is:
Attempt to invoke interface method ‘java.lang.Object java.util.List.get(int)’ on a null object reference
at com.example.ionutb.baking.ui.FragmentStepTitle.onC reateView

Why I don-t see the List value??

Show Accepted Answer

Guest Quick Reply (No URL, BBcode or HTML)

Last post by christophe.klein
2 hours ago
Last post by feeney.ruthie
50 minutes ago
Last post by schuyler.hand
4 hours ago
Help
Started by giovani.lockman
Last post by lschumm
54 minutes ago
Last post by gloria.denesik
4 hours ago
Last post by lisa92
1 hour ago
Last post by jordi78
3 hours ago
Xperia Z3
Started by ebartoletti
Last post by jo81
2 hours ago
Last post by obayer
3 hours ago
Last post by gia69
2 hours ago