I am trying to show cache size files in MB, used by my App. but my app crashing. Error : Caused by: java.lang.NullPointerException
private void initializeCache() {
long size = 0;
size += getDirSize(this.getCacheDir());
size += getDirSize(this.getExternalCacheDir());
this.text_view_cache_value.setText(getResources().getString(R.string.label_cache) + readableFileSize(size));
}
public long getDirSize(File dir){
long size = 0;
for (File file : dir.listFiles()) {
if (file != null && file.isDirectory()) {
size += getDirSize(file);
} else if (file != null && file.isFile()) {
size += file.length();
}
}
return size;
}