Search code examples
androidfile-iotoast

checking if a directory is created or not, fails?


I'm trying to create a directory, and i'm checking whether it is created successfully or not but displaying a text on the screen, but nothing to be displayed.

Java code:

public void createDirectory() {
    try {
        String strDirectory = "test";
        boolean success = ( new File(strDirectory)).mkdir();
        if (success) {
            Toast.makeText(getBaseContext(), "Directory "+strDirectory+" created", Toast.LENGTH_SHORT);
        } else {
            Toast.makeText(getApplicationContext(), "error occured", Toast.LENGTH_SHORT);
        }
    } catch (Exception e) {
        Log.e("Error", "Error creating directory");
    }
}

Solution

  • put .show() end of Both Toast....

    Toast.makeText(getBaseContext(), "Directory "+strDirectory+" created", 
    Toast.LENGTH_SHORT).show();