I am implementing a horizontal gallery in my Fragment Activity
, but I can't get my images, therefore returning a NullPointerException
:
LinearLayout myGallery;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
myGallery = (LinearLayout) getActivity().findViewById(R.id.mygallery);
String targetPath = "assets/";
Toast.makeText(getActivity(), targetPath, Toast.LENGTH_LONG).show();
File targetDirector = new File(targetPath);
File[] files = targetDirector.listFiles();
for (File file : files){ //NullPointerException here
myGallery.addView(insertPhoto(file.getAbsolutePath()));
}
}
And this is the path of my images:
The NullPointerException
points at the for loop for (File file ; files){ ...
What is the right way to reach my folder?