Caused by: java.util.IllegalFormatConversionException: f != java.lang.Long

Exception:

Caused by: java.util.IllegalFormatConversionException: f != java.lang.Long

Cause:

    private void updateSizeInfo() {
        long size = FileHelper.getDirSize(Objects.requireNonNull(getContext()).getExternalFilesDir(null));
        LogUtils.d(size);
        String strSize = size > 1 << 20 ? PalmUtils.formatString(R.string.cache_size_mb, size >> 20)
                : PalmUtils.formatString(R.string.cache_size_kb, size >> 10);
        getBinding().amiCache.setFooter(strSize);
    }

I use the code above to calculate the size of memory used, notice that I used the >> operation, here i want to write down something about the difference between >> and /.

Of course that you can use size * 1.0 / 1024 / 1024 to transfer bytes to MB, the goodness is that we can get the float result, the size >> 20 is more efficient but can only get the long result.

That is the problem, if I used >> and %1.f then i will get the exception.


版权声明:本文为github_35186068原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。