Convert a string which contains uri paths to a arraylist

I am creating a notepad programm where the user can add images to his notes . When he creates a new note and picks a few images their paths(uri) are stored in an arraylist which is converted to a xml tag (string type conversion) . When the user wants to open a created note the selected images from before are displayed in a gridview. However when i try to convert the string tag from the xml file to an arraylist so the imageadapter can put them in the grid view i am getting errors about conversion types . edit the error i get is -java.lang.String cannot be cast to

The adapter is this

`private Context ctx;
    private int pos;
    private LayoutInflater inflater;
    private ImageView ivGallery;
    ArrayList<Uri> mArrayUri;
    public GalleryAdapter(Context ctx, ArrayList<Uri> mArrayUri) {

        this.ctx = ctx;
        this.mArrayUri = mArrayUri;

    public int getCount() {
        return mArrayUri.size();

    public Object getItem(int position) {
        return mArrayUri.get(position);

    public long getItemId(int position) {
        return 0;

    public View getView(int position, View convertView, ViewGroup parent) {

        pos = position;
        inflater = (LayoutInflater) ctx

        View itemView = inflater.inflate(R.layout.gv_item, parent, false);

        ivGallery = (ImageView) itemView.findViewById(;


        return itemView;

and the way i try to convert them to array and show them in the grid view is this

`  String Paths = userData.get(1);

            ArrayList mArrayUri = new ArrayList<>(Arrays.asList(Paths.split(",")));
            galleryAdapter = new GalleryAdapter(getApplicationContext(),mArrayUri);
            ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) gvGallery
            mlp.setMargins(0, gvGallery.getHorizontalSpacing(), 0, 0);


The xml creation code is this

` xmlSerializer.startDocument("UTF-8", true);
            xmlSerializer.startTag(null, "userData");
            xmlSerializer.endTag(null, "Text");
            xmlSerializer.startTag(null,"Image Paths");
            xmlSerializer.endTag(null,"Image Paths" );
            xmlSerializer.endTag(null, "userData");


Your code is pretty good just make your array list type string and then take string value of uri.

In the .text(String.valueof(Imagepath)) use Uri.toString instead of String valueof

Example :

Uri uri;
String myUriString;
myUriString = uri.toString();

Leave a Reply

Your email address will not be published. Required fields are marked *