java.lang.NumberFormatException:对于输入字符串:“msf:126968”在android

问题描述 投票:0回答:1

所以我在尝试从代码中的图库获取图像时遇到此错误。所以我正在获取图像并使用 sillicompressor 库来压缩图像,我在这条压缩线上遇到了这个错误

" 文件 file = new File(SiliCompressor.with(getContext()).compress(FileUtils.getPath(getContext(), imageuri), new File(getContext().getCacheDir(), "temp" + i))) ;“

代码

    activityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
        @Override
        public void onActivityResult(ActivityResult result) {


            if (result.getResultCode() == RESULT_OK && null != result.getData()) {

                if (result.getData().getClipData() != null) {
                    int countofImages = result.getData().getClipData().getItemCount();


                        //this part is to select multiple images
                        for (int i = 0; i < countofImages; i++) {

                            if (imageList.size() < 8)
                            {
                                 imageuri = result.getData().getClipData().getItemAt(i).getUri();

                                File file = new File(SiliCompressor.with(getContext()).compress(FileUtils.getPath(getContext(), imageuri), new File(getContext().getCacheDir(), "temp" + i)));
                                compresseduri = Uri.fromFile(file);


                                imageList.add(new CustomModel(getfilename(imageuri), compresseduri));
                            } else
                                {
                                Toast.makeText(getContext(), "Can't select more than 8 images", Toast.LENGTH_SHORT).show();
                            }
                        }
                        //then notify the adapter
                    adapter.notifyDataSetChanged();
                    rentSell3Binding.totalphotos.setText("Photos (" + imageList.size() + ")");

                    }
                    //this part is to select single image
                    else {
                    if (imageList.size()<8) {
                         imageuri = result.getData().getData();

                        File file = new File(SiliCompressor.with(getContext()).compress(FileUtils.getPath(getContext(), imageuri), new File(getContext().getCacheDir(), "temp")));

                        compresseduri = Uri.fromFile(file);

                        imageList.add(new CustomModel(getfilename(imageuri), compresseduri));

                    }else
                    {

                        Toast.makeText(getContext(), "Can't select more than 8 images", Toast.LENGTH_SHORT).show();

                    }

                    //notify the adapter
                    adapter.notifyDataSetChanged();
                    rentSell3Binding.totalphotos.setText("Photos (" + imageList.size() + ")");

                    }
            } 

我遇到错误

 java.lang.NumberFormatException: For input string: "msf:126968" on this line 
     File file = new File(SiliCompressor.with(getContext()).compress(FileUtils.getPath(getContext(), imageuri), new File(getContext().getCacheDir(), "temp" + i)));"
java android android-studio numberformatexception
1个回答
0
投票

我也遇到这个问题了。我使用https://gist.github.com/tatocaster/32aad15f6e0c50311626 在我的代码中,它一直工作到 api 29...有人可以回答这个问题吗?谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.