I have a weird problem with my android File.exists functionality. Below is my code
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.fragment_file_browser, container);
DataBaseHelper tmpHelper = new DataBaseHelper(getActivity());
ButtonInfoContainer infoContainer = tmpHelper.getVideoWithId(videoId);
//Tmp way to use this. When UX is finished will create a better way.
File f = new File(Environment.getExternalStorageDirectory() + "/aslkfj");
Log.i(StaticValues.TAG, Environment.getExternalStorageDirectory() + "/aslkfj");
LinearLayout tmpView2 = (LinearLayout) view.findViewById(R.id.custom_recordings);
if(f.exists());
{
Log.i(StaticValues.TAG, "f exists");
String[] tmp = f.list();
View tmpView = null;
if(tmp != null)
{
for(int i = 0; i < tmp.length; i ++)
{
tmpView = inflater.inflate(R.layout.list_item, null);
TextView tmpText = (TextView) tmpView.findViewById(R.id.product_name);
tmpText.setText(tmp[i]);
tmpView2.addView(tmpView);
}
}
}
return view;
}
Everything is cool but the weird part is that File.exists returns a false positive for me. It always says that the file exists (just in this app though). the path given above /aslkfj does not exist but when I run this code my logcat outputs f exists. Why would something like that happen.
You have a
semi-colonat the end of yourifcondition: –Due to this, the following block is just a local block, which will be executed regardless of what your if condition evaluate to.