-1

I know this seems like a stupid question, but it is driving me nuts.

I am trying to display the value of folder_sizein my toast, but I get the error:

The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (Context, long, int)

  File file = new File(Environment.getExternalStorageDirectory().getPath() + "/X ADB/");
  long folder_size = getFolderSize(file);

  Toast.makeText(getApplicationContext(),folder_size, Toast.LENGTH_LONG).show();

  }

  public static long getFolderSize(File dir) {
    long size = 0;
    for (File file : dir.listFiles()) {
        if (file.isFile()) {
            // System.out.println(file.getName() + " " + file.length());
            size += file.length();
        } else
            size += getFolderSize(file);
    }
    return size;
  }
}

This is the solution I have found, but I need to add an additional text in my toast, which I don't want. How do I remove this error?

Toast.makeText(getApplicationContext(),folder_size+ " text", Toast.LENGTH_LONG).show();
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96

4 Answers4

2

You can also use String.valueOf(long).

Toast.makeText(getApplicationContext(),
        String.valueOf(folder_size), 
        Toast.LENGTH_LONG)
        .show();
terryk
  • 116
  • 7
1

You don't need to add any text in your toast, just append your long value with empty string like this

Toast.makeText(getApplicationContext(),""+folder_size, Toast.LENGTH_LONG).show();

hope this will work

Mayur Kharche
  • 717
  • 1
  • 8
  • 27
0
Toast.makeText(getApplicationContext(),Long.toString(folder_size), Toast.LENGTH_LONG).show();

You can covert long into String without + sign

Fernando Tan
  • 634
  • 4
  • 14
0

I would do the following. This is a fairly standard way of achieving what you want. You need to convert your long to a string. Below is a very common way of doing this.

Toast.makeText(getApplicationContext(), folder_size + "", Toast.LENGTH_LONG).show();
Brandon Tripp
  • 277
  • 1
  • 3
  • 16