Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取java.lang.IllegalArgumentException:通过我的应用程序从内部存储中删除多个文件时URL未知_Java_Android_Image_Image Processing_Internals - Fatal编程技术网

获取java.lang.IllegalArgumentException:通过我的应用程序从内部存储中删除多个文件时URL未知

获取java.lang.IllegalArgumentException:通过我的应用程序从内部存储中删除多个文件时URL未知,java,android,image,image-processing,internals,Java,Android,Image,Image Processing,Internals,在这里,我通过Adapter(Adapter for recyclerView)类中的复选框将图像保存在arraylist(名称:aaa{type ModalClass})中的arraylist(名称:selectedImages{type-String})中。 if (ck){holder.checkBox.setVisibility(View.VISIBLE);} holder.checkBox.setOnClickListener(new View.OnClickListe

在这里,我通过Adapter(Adapter for recyclerView)类中的复选框将图像保存在arraylist(名称:aaa{type ModalClass})中的arraylist(名称:selectedImages{type-String})中。

if (ck){holder.checkBox.setVisibility(View.VISIBLE);}
        holder.checkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                
                if (aaa.get(position).isSelected()) {
                    aaa.get(position).setSelected(false);
                } else {
                    aaa.get(position).setSelected(true);
                    selectedImages.add(aaa.get(position).getImage().toString());
                    Toast.makeText(context,aaa.get(position).getImage().toString(),Toast.LENGTH_LONG).show();
                }
                
            }
        });
2021-04-10 07:13:19.527 2056-2056/com.example.gallery30 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.gallery30, PID: 2056
    java.lang.IllegalArgumentException: Unknown URL /file:/storage/emulated/0/Documents%20(1)/Pinkesh%20Documents/Reshan%20card2.jpg
        at android.content.ContentResolver.delete(ContentResolver.java:2288)
        at android.content.ContentResolver.delete(ContentResolver.java:2258)
        at com.example.gallery30.MainActivity$1.onClick(MainActivity.java:76)
        at android.view.View.performClick(View.java:8160)
        at android.widget.TextView.performClick(TextView.java:16222)
        at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
        at android.view.View.performClickInternal(View.java:8137)
        at android.view.View.access$3700(View.java:888)
        at android.view.View$PerformClick.run(View.java:30236)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:246)
        at android.app.ActivityThread.main(ActivityThread.java:8506)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
在这里,我试图从一个按钮(用于删除)的onclicklistoner中的数组(selectedImages)中删除图像。

这是我的主要活动代码

delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                for(int i = 0; i<a.selectedImages.size(); i++) {

                    File imageFile= new File(a.selectedImages.get(i));

                    String pathh= imageFile.getAbsolutePath();

                    getContentResolver().delete(Uri.parse(pathh),null,null);

                    MainActivity.this.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.fromFile(imageFile)));
                }
                a.selectedImages.clear();
                a.notifyDataSetChanged();

            }
        });
public class MainActivity extends AppCompatActivity implements OnItemClickListioner {
    RecyclerView recyclerView;
    String[] arrPath;
    String[] permissions= {Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.CAMERA,Manifest.permission.INTERNET};
    public Adapter a;
    Button delete;
    ImageView imageViewforshowimage;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        recyclerView= findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new GridLayoutManager(MainActivity.this,3));
        a=new Adapter(MainActivity.this,getData(), this,arrPath);
        recyclerView.setAdapter(a);
        delete= findViewById(R.id.delete);

        TextView textView= findViewById(R.id.textView2);
        imageViewforshowimage= findViewById(R.id.imageView3);

        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                for(int i = 0; i<a.selectedImages.size(); i++) {

                    File imageFile= new File(a.selectedImages.get(i));

                    String pathh= imageFile.getAbsolutePath();

                    getContentResolver().delete(Uri.parse(pathh),null,null);

                    MainActivity.this.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.fromFile(imageFile)));
                }
                a.selectedImages.clear();
                a.notifyDataSetChanged();

            }
        });


        if(ContextCompat.checkSelfPermission(this,Manifest.permission.READ_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED){
            ActivityCompat.requestPermissions(this,permissions,101);

        }
}


    @Override
    public void picClick(viewHolder holder, int position, ArrayList<ModelClass> mpic) {
        Intent intent= new Intent(MainActivity.this,MainActivity2.class);
        intent.putExtra("p",arrPath[position]);
        startActivity(intent);
    }

    @Override
    public void picLongClick(viewHolder holder, int position, ArrayList<ModelClass> mpic) {
        Toast.makeText(MainActivity.this,"You Pressed",Toast.LENGTH_SHORT).show();



    }
    public ArrayList<ModelClass> getData(){
        final String[] column= {MediaStore.Images.Media.DATA,MediaStore.Images.Media._ID};
        final String orderby= MediaStore.Images.Media._ID;

        ArrayList<ModelClass> xMan= new ArrayList<>();

        Cursor cursor= getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,column,null,null,orderby);
        int count= cursor.getCount();
        arrPath= new String[count];
        for(int i= 0;i<count;i++){
            ModelClass modelClass= new ModelClass();
            cursor.moveToPosition(i);


            int datacolumnindex= cursor.getColumnIndex(MediaStore.Images.Media.DATA);
            arrPath[i]= cursor.getString(datacolumnindex);
            File file= new File(arrPath[i]);
            modelClass.setName(file.getName());
            modelClass.setImagepath(file.getPath());
            modelClass.setImage(Uri.fromFile(file));
            xMan.add(modelClass);
        }
        return xMan;

    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        if(requestCode==101){
            if(grantResults.length>0 && grantResults[0]==PackageManager.PERMISSION_GRANTED){


            }
        }
    }

}

**MainActivity2用于显示大图像,同时单击recyclerView…Thamks中的图像缩略图以提前获得帮助。我不仅是安卓系统的实习生,也是编程的实习生。**

????你的问题是什么?例如,imageFile.getAbsolutePath()的值是多少?你在哪里删除文件?很抱歉没有提到我的日志输出。我已经编辑了我的问题,所以请帮帮我…我正在制作一个简单的画廊应用程序。我的天。。我不想把那件事全部讲清楚。。太多不相关的代码。只有要删除的代码必须以您使用的url/path/uri开头显示。不多了。请删除所有内容并发布最简单的删除代码。请帮助我…我被这个问题困扰了一周…请您给我任何类型的联系人来解决这个问题,先生。。。
  public class Adapter extends RecyclerView.Adapter<viewHolder> {

  public ArrayList<ModelClass> aaa=new ArrayList<>();
  public Context context;
  public Boolean ck=false;
  public ArrayList<String> selectedImages= new ArrayList<>();
  public ArrayList<CheckBox> checkmate= new ArrayList<>();
  private final OnItemClickListioner picListerner;
  public String[] arraypathadapter;
  public String checkedstring;
  private OnItemCheckListener onItemClick;

  interface OnItemCheckListener {
      void onItemCheck(ClipData.Item item);
      void onItemUncheck(ClipData.Item item);
  }

  public Adapter(Context c, ArrayList<ModelClass> aaa, OnItemClickListioner picListerner, String[] arraypathadapter) {
      this.aaa = aaa;
      this.context= c;
      this.picListerner = picListerner;
      this.arraypathadapter= arraypathadapter;
  }


  @NonNull
  @Override
  public viewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
      LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
      View view = layoutInflater.inflate(R.layout.single_cell, null, false);

      return new viewHolder(view);
  }

  @Override
  public void onBindViewHolder(@NonNull viewHolder holder, int position) {
      ModelClass m = aaa.get(position);
      holder.textView.setText(m.getname());
      holder.checkBox.setChecked(aaa.get(position).isSelected());
      Glide.with(context).load(m.getImage()).placeholder(R.drawable.placeholder_image).into(holder.imageView);



      if (ck){holder.checkBox.setVisibility(View.VISIBLE);}
      holder.checkBox.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {

              if (aaa.get(position).isSelected()) {
                  aaa.get(position).setSelected(false);
              } else {
                  aaa.get(position).setSelected(true);
                  selectedImages.add(aaa.get(position).getImage().toString());
                  Toast.makeText(context,aaa.get(position).getImage().toString(),Toast.LENGTH_LONG).show();
              }

          }
      });



      holder.imageView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              picListerner.picClick(holder,position,aaa);
          }
      });

      holder.imageView.setOnLongClickListener(new View.OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
              picListerner.picLongClick(holder,position,aaa);

               ck = true;

              notifyDataSetChanged();

              return true;
          }
      });
  }
  @Override
  public int getItemCount () {
      return aaa.size();
  }}
public interface OnItemClickListioner {
    public void picClick(viewHolder holder, int position, ArrayList<ModelClass> mpic);
    public void picLongClick(viewHolder holder, int position, ArrayList<ModelClass> mpic);
}
 public class ModelClass {
 private String name;
 private Uri image;
 private CheckBox checkBox;
 private String imagepath;
 private boolean isSelected;

  public boolean isSelected() {
      return isSelected;
  }

  public void setSelected(boolean selected) {
      isSelected = selected;
  }

  public String getImagepath() {
      return imagepath;
  }

  public void setImagepath(String imagepath) {
      this.imagepath = imagepath;
  }

  public CheckBox getCheckBox() {
      return checkBox;
  }

  public void setCheckBox(CheckBox checkBox) {
      this.checkBox = checkBox;
  }

  public String getname() {
      return name;
  }

  public void setName(String name) {
      this.name = name;
  }

  public Uri getImage() {
      return image;
  }

  public void setImage(Uri image) {
      this.image = image;
  }}