问:
How to get values from a particular ID using JSON in CardView in Android
I want to develop an Android app using recyclerview CardView, getting data from JSON file.

The error I am facing is I'm getting the images and text for all users, rather than just a particular user's data, in a particular post (like Facebook).

Here is my JSON code:

```<code>{
    "posts": [{
        "post_id": "59",
        "post_desc": "",
        "firstname": "karan",
        "lastname": "qq",
        "created_at": "2017-05-30 23:17:46",
        "files": [{
            "file_name": "1496166466_IMG-20170529-WA0041.jpg",
            "file_type": "1"
        }]
    }, {
        "post_id": "58",
        "post_desc": "\ud83d\ude0d\ud83d\ude0a",
        "firstname": "karan",
        "lastname": "qq",
        "created_at": "2017-05-30 12:12:36",
        "files": []
    }, {
        "post_id": "57",
        "post_desc": "Good Morning",
        "firstname": "karan",
        "lastname": "qq",
        "created_at": "2017-05-30 11:29:43",
        "files": []
    }, {
        "post_id": "56",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-26 16:50:49",
        "files": []
    }, {
        "post_id": "55",
        "post_desc": "",
        "firstname": "jaxi",
        "lastname": "chawda",
        "created_at": "2017-05-26 16:50:04",
        "files": []
    }, {
        "post_id": "54",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-26 16:47:24",
        "files": [{
            "file_name": "1495797444_IMG_20170522_191006_842.jpg",
            "file_type": "1"
        }]
    }, {
        "post_id": "53",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-26 16:45:18",
        "files": []
    }, {
        "post_id": "52",
        "post_desc": "",
        "firstname": "jaxi",
        "lastname": "chawda",
        "created_at": "2017-05-26 16:32:24",
        "files": []
    }, {
        "post_id": "51",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-26 16:18:31",
        "files": []
    }, {
        "post_id": "50",
        "post_desc": "",
        "firstname": "karan",
        "lastname": "qq",
        "created_at": "2017-05-23 17:37:19",
        "files": [{
            "file_name": "1495541239_VID-20170518-WA0029.mp4",
            "file_type": "2"
        }]
    }, {
        "post_id": "49",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-16 16:19:13",
        "files": [{
            "file_name": "1494931753_IMG_3919.mp4",
            "file_type": "2"
        }]
    }, {
        "post_id": "48",
        "post_desc": "",
        "firstname": "jaxi",
        "lastname": "chawda",
        "created_at": "2017-05-16 15:09:32",
        "files": [{
            "file_name": "1494927572_Technology in the Future.mp4",
            "file_type": "2"
        }]
    }, {
        "post_id": "47",
        "post_desc": "",
        "firstname": "pankti",
        "lastname": "shah",
        "created_at": "2017-05-16 13:30:09",
        "files": [{
            "file_name": "1494921609_Tom and Jerry - Little School Mouse.mp4",
            "file_type": "2"
        }]
    }, {
        "post_id": "46",
        "post_desc": "",
        "firstname": "pankti",
        "lastname": "shah",
        "created_at": "2017-05-16 13:16:34",
        "files": [{
            "file_name": "1494920794_Tubelight _ Official Teaser _ Salman Khan _ Kabir Khan.mp4",
            "file_type": "2"
        }]
    }, {
        "post_id": "45",
        "post_desc": "",
        "firstname": "pankti",
        "lastname": "shah",
        "created_at": "2017-05-16 13:13:51",
        "files": [{
            "file_name": "1494920631_small.mp4",
            "file_type": "2"
        }]
    }, {
        "post_id": "44",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-13 16:45:08",
        "files": [{
            "file_name": "1494674108_IMG_4126.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "43",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-13 16:24:30",
        "files": [{
            "file_name": "1494672870_IMG_4123.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "42",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-13 16:23:25",
        "files": [{
            "file_name": "1494672805_IMG_4124.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "41",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-13 15:48:39",
        "files": [{
            "file_name": "1494670719_IMG_4121.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "40",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-12 22:53:24",
        "files": [{
            "file_name": "1494609804_IMG_4119.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "39",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-12 18:28:28",
        "files": [{
            "file_name": "1494593908_IMG_4015.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "38",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-12 14:13:20",
        "files": [{
            "file_name": "1494578600_IMG_4113.PNG",
            "file_type": "1"
        }]
    }, {
        "post_id": "37",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-12 14:13:18",
        "files": [{
            "file_name": "1494578598_IMG_4113.PNG",
            "file_type": "1"
        }]
    }, {
        "post_id": "36",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-12 14:13:15",
        "files": [{
            "file_name": "1494578595_IMG_4113.PNG",
            "file_type": "1"
        }]
    }, {
        "post_id": "35",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-12 14:13:12",
        "files": [{
            "file_name": "1494578592_IMG_4113.PNG",
            "file_type": "1"
        }]
    }, {
        "post_id": "34",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-12 14:13:09",
        "files": [{
            "file_name": "1494578589_IMG_4113.PNG",
            "file_type": "1"
        }]
    }, {
        "post_id": "33",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:43:42",
        "files": [{
            "file_name": "1494526422_IMG_3950.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "32",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:43:10",
        "files": [{
            "file_name": "1494526390_IMG_3944.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "31",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:26:24",
        "files": [{
            "file_name": "1494525384_IMG_3127.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "30",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:26:20",
        "files": [{
            "file_name": "1494525380_IMG_3127.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "29",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:24:12",
        "files": [{
            "file_name": "1494525252_IMG_2600.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "28",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:24:06",
        "files": [{
            "file_name": "1494525246_IMG_2600.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "27",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:22:04",
        "files": [{
            "file_name": "1494525124_IMG_3113.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "26",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:21:11",
        "files": [{
            "file_name": "1494525071_1491304854804.jpeg",
            "file_type": "1"
        }]
    }, {
        "post_id": "25",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:20:26",
        "files": [{
            "file_name": "1494525026_IMG_4050.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "24",
        "post_desc": "Ganesh Mahotsav 2016 ",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:20:01",
        "files": [{
            "file_name": "1494525001_IMG_4045.PNG",
            "file_type": "1"
        }]
    }, {
        "post_id": "23",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:19:03",
        "files": [{
            "file_name": "1494524943_IMG_4016.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "22",
        "post_desc": "\ud83d\ude0d\n",
        "firstname": "karan",
        "lastname": "qq",
        "created_at": "2017-05-10 14:57:16",
        "files": []
    }, {
        "post_id": "21",
        "post_desc": "\ud83d\ude0a\n",
        "firstname": "karan",
        "lastname": "qq",
        "created_at": "2017-05-04 11:06:07",
        "files": []
    }, {
        "post_id": "20",
        "post_desc": "\ud83d\ude0a\n",
        "firstname": "karan",
        "lastname": "qq",
        "created_at": "2017-05-04 11:06:03",
        "files": []
    }, {
        "post_id": "19",
        "post_desc": "Good morning",
        "firstname": "karan",
        "lastname": "qq",
        "created_at": "2017-05-04 11:05:27",
        "files": []
    }, {
        "post_id": "18",
        "post_desc": "https:\/\/www.youtube.com\/watch?v=Qtp42J9IOUo",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 16:39:53",
        "files": []
    }, {
        "post_id": "17",
        "post_desc": "\ud83d\ude1c\ud83d\ude1c\ud83d\ude1c\ud83d\ude1c\ud83d\ude1c\ud83d\ude1c\ud83d\ude1c",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 16:38:40",
        "files": []
    }, {
        "post_id": "16",
        "post_desc": "hi hello",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 16:30:35",
        "files": []
    }, {
        "post_id": "15",
        "post_desc": "\ud83d\ude0e\ud83d\ude34\ud83d\ude01",
        "firstname": "Manish",
        "lastname": "Amin",
        "created_at": "2017-05-02 16:30:19",
        "files": []
    }, {
        "post_id": "14",
        "post_desc": "\ud83d\ude0e\ud83d\ude34\ud83d\ude01",
        "firstname": "Manish",
        "lastname": "Amin",
        "created_at": "2017-05-02 16:30:17",
        "files": []
    }, {
        "post_id": "13",
        "post_desc": "\ud83d\ude0e\ud83d\ude34\ud83d\ude01",
        "firstname": "Manish",
        "lastname": "Amin",
        "created_at": "2017-05-02 16:30:17",
        "files": []
    }, {
        "post_id": "12",
        "post_desc": "\ud83d\ude0e\ud83d\ude34\ud83d\ude01",
        "firstname": "Manish",
        "lastname": "Amin",
        "created_at": "2017-05-02 16:30:16",
        "files": []
    }, {
        "post_id": "11",
        "post_desc": "\ud83d\ude0e\ud83d\ude34\ud83d\ude01",
        "firstname": "Manish",
        "lastname": "Amin",
        "created_at": "2017-05-02 16:30:16",
        "files": []
    }, {
        "post_id": "10",
        "post_desc": "\ud83d\ude0a\ud83d\ude0a\ud83d\ude04\ud83d\ude04\u263a\ufe0f\ud83d\ude01\ud83d\ude01",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 16:30:14",
        "files": []
    }, {
        "post_id": "9",
        "post_desc": "Going to receive loads of money....",
        "firstname": "Manish",
        "lastname": "Amin",
        "created_at": "2017-05-02 16:08:58",
        "files": []
    }, {
        "post_id": "8",
        "post_desc": "\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 16:08:57",
        "files": []
    }, {
        "post_id": "7",
        "post_desc": "\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 16:08:55",
        "files": []
    }, {
        "post_id": "6",
        "post_desc": "\ud83d\ude02\ud83d\ude02\ud83d\ude02\ud83d\ude02",
        "firstname": "Abc",
        "lastname": "Xyz",
        "created_at": "2017-05-02 16:08:47",
        "files": []
    }, {
        "post_id": "5",
        "post_desc": "\ud83c\udfe1\ud83c\udfeb",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 16:05:40",
        "files": []
    }, {
        "post_id": "4",
        "post_desc": "\ud83d\udc4d\ud83d\udc4d\ud83d\ude0a\ud83d\ude12\ud83d\udc2e\ud83d\ude48\ud83d\ude1c\ud83d\ude09\ud83d\ude03",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 16:02:21",
        "files": []
    }, {
        "post_id": "3",
        "post_desc": "\ud83d\ude12\ud83d\ude0a",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 15:58:42",
        "files": []
    }, {
        "post_id": "2",
        "post_desc": "\ud83d\ude33\ud83d\ude33\ud83d\ude33",
        "firstname": "jaxi",
        "lastname": "chawda",
        "created_at": "2017-05-02 15:57:31",
        "files": []
    }, {
        "post_id": "1",
        "post_desc": "hii....good afternoon...\ud83d\ude04\ud83d\ude04\ud83d\ude04",
        "firstname": "jaxi",
        "lastname": "chawda",
        "created_at": "2017-05-02 15:55:49",
        "files": []
    }]
}
</code>```

Here is my Android code:

```<code>   String filename = "";
            try {
                JSONObject jsonObject = new JSONObject(s);
                JSONArray posts = jsonObject.getJSONArray("posts");
                if(posts != null && posts.length() > 0 ) {
                    for (int i = 0; i < posts.length(); i++) {
                        JSONObject fileObj = posts.getJSONObject(i);

                        String fName = fileObj.getString("firstname");
                        String created_at = fileObj.getString("created_at");
                        String post_desc = fileObj.getString("post_desc");

                        Log.e("Details", fName + "" + created_at + "" + post_desc);

                        JSONArray files = fileObj.getJSONArray("files");
                        if(files != null && files.length() > 0 ) {

                            for (int j = 0; j < files.length(); j++) {
                                JSONObject Jsonfilename = files.getJSONObject(j);
                                filename = Jsonfilename.getString("file_name");
                                filename = "www.sample.com/home_webservice/compress/"+filename;
                                Log.e("Files", "" + filename);
                            }
                        }

                        Data_SAerver item = new Data_SAerver(fName,created_at,post_desc,filename);
                        data_sAervers.add(item);
                    }
                }

          adapter = new MyAdapter(data_sAervers,getApplicationContext());

                recyclerView.setAdapter(adapter);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            progressDialog.dismiss();

            Toast.makeText(getApplicationContext(), error.getMessage(),Toast.LENGTH_LONG).show();

        }
    });

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
}
}
</code>```

DATA SERVER CLASS CODE

```<code>public class Data_SAerver {

    private String firstname;
    private  String created_at;
    private  String post_desc;

    private String filepath; /*= "http://cleanvadodara.esy.es/images/";*/

    public Data_SAerver(String firstname, String created_at, String post_desc,String filepath)
    { this.firstname = firstname;
        this.created_at = created_at;
        this.post_desc = post_desc;
        this.filepath = filepath;
    }
    public String getfilepath()
    { return filepath; }

    public Data_SAerver(String firstname, String created_at, String post_desc) {
        this.firstname = firstname;
        this.created_at = created_at;
        this.post_desc = post_desc;

    }

    public String getFirstname() {
        return firstname;
    }

    public String getCreated_at() {
        return created_at;
    }

    public String getPost_desc() {
        return post_desc;
    }

}
</code>```

MY ADAPTER CLASS

```<code>public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
    private List<Data_SAerver> data_sAervers;

    private Context context;
    public MyAdapter(List<Data_SAerver> data_sAervers, Context context) {
        this.data_sAervers = data_sAervers;
        this.context = context;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.sample, parent, false);
        return new ViewHolder(v);
    }
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        Data_SAerver data_sAerver = data_sAervers.get(position);
        holder.firstname.setText(data_sAerver.getFirstname());
        holder.created_at.setText(data_sAerver.getCreated_at());
        holder.post_desc.setText(data_sAerver.getPost_desc());
        Picasso.with(context).load(data_sAerver.getfilepath()).resize(736,1128).onlyScaleDown().into(holder.files);
   }

    @Override
    public int getItemCount() {
        return data_sAervers.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{

        public TextView firstname;
        public TextView created_at;
        public  TextView post_desc;
        public ImageView files;
        boolean isImageFitToScreen;

        public ViewHolder(View itemView) {
            super(itemView);

            firstname = (TextView) itemView.findViewById(R.id.firstname);
            created_at = (TextView) itemView.findViewById(R.id.created_at);
            post_desc= (TextView)itemView.findViewById(R.id.post_desc);
            files = (ImageView) itemView.findViewById(R.id.image_files);

         //   ImageViewPopUpHelper.enablePopUpOnClick(ViewHolder.this, files);

           /* files.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(isImageFitToScreen) {
                        isImageFitToScreen=true;
                        files.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
                        files.setAdjustViewBounds(true);
                    }else{
                        isImageFitToScreen=false;
                        files.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
                        files.setScaleType(ImageView.ScaleType.FIT_XY);
                    }
                }
            });*/

        }
    }

}
</code>```

Please help to solve this error. Thank you.

答:
This is my activity code </p>

```<code><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:cardview="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:padding="5dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="wrap_content">

            <android.support.v7.widget.CardView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:padding="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/iconone"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_marginBottom="5dp"
                    android:layout_marginLeft="5dp"
                    android:src="@drawable/logo" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/firstname"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:gravity="start"
                        android:text="Karan Brahmaxatriya"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textColor="#2196fe" />

                    <TextView

                        android:id="@+id/created_at"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:gravity="start"
                        android:text="23/05/2017  6:05 PM"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textColor="#333333"
                        android:textSize="16sp" />

                </LinearLayout>

            </LinearLayout>

            <ImageView
                android:id="@+id/image_files"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                 />
            <TextView
                android:id="@+id/filepathurl"
                android:visibility="gone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="filepathurl"/>
            <TextView
                android:id="@+id/playvideo"
                android:visibility="gone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="playvideo"/>
          <VideoView
              android:id="@+id/videoView"
              android:visibility="gone"
              android:layout_width="fill_parent"
              android:layout_height="190dp" />
            <TextView
                android:id="@+id/post_desc"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="start"
                android:layout_marginLeft="5dp"
                android:text="ccvvzv"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#333333" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1">

                <Button
                    android:id="@+id/comment_btn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Comment" />

                <Button
                    android:id="@+id/repost_btn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Repost" />

                <Button
                    android:id="@+id/like_btn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Like" />
            </LinearLayout>
        </LinearLayout>

    </android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</code>```

Body:
I want to develop an Android app using recyclerview CardView, getting data from JSON file.

The error I am facing is I'm getting the images and text for all users, rather than just a particular user's data, in a particular post (like Facebook).

Here is my JSON code:

{
    "posts": [{
        "post_id": "59",
        "post_desc": "",
        "firstname": "karan",
        "lastname": "qq",
        "created_at": "2017-05-30 23:17:46",
        "files": [{
            "file_name": "1496166466_IMG-20170529-WA0041.jpg",
            "file_type": "1"
        }]
    }, {
        "post_id": "58",
        "post_desc": "\ud83d\ude0d\ud83d\ude0a",
        "firstname": "karan",
        "lastname": "qq",
        "created_at": "2017-05-30 12:12:36",
        "files": []
    }, {
        "post_id": "57",
        "post_desc": "Good Morning",
        "firstname": "karan",
        "lastname": "qq",
        "created_at": "2017-05-30 11:29:43",
        "files": []
    }, {
        "post_id": "56",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-26 16:50:49",
        "files": []
    }, {
        "post_id": "55",
        "post_desc": "",
        "firstname": "jaxi",
        "lastname": "chawda",
        "created_at": "2017-05-26 16:50:04",
        "files": []
    }, {
        "post_id": "54",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-26 16:47:24",
        "files": [{
            "file_name": "1495797444_IMG_20170522_191006_842.jpg",
            "file_type": "1"
        }]
    }, {
        "post_id": "53",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-26 16:45:18",
        "files": []
    }, {
        "post_id": "52",
        "post_desc": "",
        "firstname": "jaxi",
        "lastname": "chawda",
        "created_at": "2017-05-26 16:32:24",
        "files": []
    }, {
        "post_id": "51",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-26 16:18:31",
        "files": []
    }, {
        "post_id": "50",
        "post_desc": "",
        "firstname": "karan",
        "lastname": "qq",
        "created_at": "2017-05-23 17:37:19",
        "files": [{
            "file_name": "1495541239_VID-20170518-WA0029.mp4",
            "file_type": "2"
        }]
    }, {
        "post_id": "49",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-16 16:19:13",
        "files": [{
            "file_name": "1494931753_IMG_3919.mp4",
            "file_type": "2"
        }]
    }, {
        "post_id": "48",
        "post_desc": "",
        "firstname": "jaxi",
        "lastname": "chawda",
        "created_at": "2017-05-16 15:09:32",
        "files": [{
            "file_name": "1494927572_Technology in the Future.mp4",
            "file_type": "2"
        }]
    }, {
        "post_id": "47",
        "post_desc": "",
        "firstname": "pankti",
        "lastname": "shah",
        "created_at": "2017-05-16 13:30:09",
        "files": [{
            "file_name": "1494921609_Tom and Jerry - Little School Mouse.mp4",
            "file_type": "2"
        }]
    }, {
        "post_id": "46",
        "post_desc": "",
        "firstname": "pankti",
        "lastname": "shah",
        "created_at": "2017-05-16 13:16:34",
        "files": [{
            "file_name": "1494920794_Tubelight _ Official Teaser _ Salman Khan _ Kabir Khan.mp4",
            "file_type": "2"
        }]
    }, {
        "post_id": "45",
        "post_desc": "",
        "firstname": "pankti",
        "lastname": "shah",
        "created_at": "2017-05-16 13:13:51",
        "files": [{
            "file_name": "1494920631_small.mp4",
            "file_type": "2"
        }]
    }, {
        "post_id": "44",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-13 16:45:08",
        "files": [{
            "file_name": "1494674108_IMG_4126.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "43",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-13 16:24:30",
        "files": [{
            "file_name": "1494672870_IMG_4123.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "42",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-13 16:23:25",
        "files": [{
            "file_name": "1494672805_IMG_4124.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "41",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-13 15:48:39",
        "files": [{
            "file_name": "1494670719_IMG_4121.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "40",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-12 22:53:24",
        "files": [{
            "file_name": "1494609804_IMG_4119.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "39",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-12 18:28:28",
        "files": [{
            "file_name": "1494593908_IMG_4015.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "38",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-12 14:13:20",
        "files": [{
            "file_name": "1494578600_IMG_4113.PNG",
            "file_type": "1"
        }]
    }, {
        "post_id": "37",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-12 14:13:18",
        "files": [{
            "file_name": "1494578598_IMG_4113.PNG",
            "file_type": "1"
        }]
    }, {
        "post_id": "36",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-12 14:13:15",
        "files": [{
            "file_name": "1494578595_IMG_4113.PNG",
            "file_type": "1"
        }]
    }, {
        "post_id": "35",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-12 14:13:12",
        "files": [{
            "file_name": "1494578592_IMG_4113.PNG",
            "file_type": "1"
        }]
    }, {
        "post_id": "34",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-12 14:13:09",
        "files": [{
            "file_name": "1494578589_IMG_4113.PNG",
            "file_type": "1"
        }]
    }, {
        "post_id": "33",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:43:42",
        "files": [{
            "file_name": "1494526422_IMG_3950.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "32",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:43:10",
        "files": [{
            "file_name": "1494526390_IMG_3944.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "31",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:26:24",
        "files": [{
            "file_name": "1494525384_IMG_3127.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "30",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:26:20",
        "files": [{
            "file_name": "1494525380_IMG_3127.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "29",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:24:12",
        "files": [{
            "file_name": "1494525252_IMG_2600.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "28",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:24:06",
        "files": [{
            "file_name": "1494525246_IMG_2600.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "27",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:22:04",
        "files": [{
            "file_name": "1494525124_IMG_3113.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "26",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:21:11",
        "files": [{
            "file_name": "1494525071_1491304854804.jpeg",
            "file_type": "1"
        }]
    }, {
        "post_id": "25",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:20:26",
        "files": [{
            "file_name": "1494525026_IMG_4050.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "24",
        "post_desc": "Ganesh Mahotsav 2016 ",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:20:01",
        "files": [{
            "file_name": "1494525001_IMG_4045.PNG",
            "file_type": "1"
        }]
    }, {
        "post_id": "23",
        "post_desc": "",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-11 23:19:03",
        "files": [{
            "file_name": "1494524943_IMG_4016.JPG",
            "file_type": "1"
        }]
    }, {
        "post_id": "22",
        "post_desc": "\ud83d\ude0d\n",
        "firstname": "karan",
        "lastname": "qq",
        "created_at": "2017-05-10 14:57:16",
        "files": []
    }, {
        "post_id": "21",
        "post_desc": "\ud83d\ude0a\n",
        "firstname": "karan",
        "lastname": "qq",
        "created_at": "2017-05-04 11:06:07",
        "files": []
    }, {
        "post_id": "20",
        "post_desc": "\ud83d\ude0a\n",
        "firstname": "karan",
        "lastname": "qq",
        "created_at": "2017-05-04 11:06:03",
        "files": []
    }, {
        "post_id": "19",
        "post_desc": "Good morning",
        "firstname": "karan",
        "lastname": "qq",
        "created_at": "2017-05-04 11:05:27",
        "files": []
    }, {
        "post_id": "18",
        "post_desc": "https:\/\/www.youtube.com\/watch?v=Qtp42J9IOUo",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 16:39:53",
        "files": []
    }, {
        "post_id": "17",
        "post_desc": "\ud83d\ude1c\ud83d\ude1c\ud83d\ude1c\ud83d\ude1c\ud83d\ude1c\ud83d\ude1c\ud83d\ude1c",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 16:38:40",
        "files": []
    }, {
        "post_id": "16",
        "post_desc": "hi hello",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 16:30:35",
        "files": []
    }, {
        "post_id": "15",
        "post_desc": "\ud83d\ude0e\ud83d\ude34\ud83d\ude01",
        "firstname": "Manish",
        "lastname": "Amin",
        "created_at": "2017-05-02 16:30:19",
        "files": []
    }, {
        "post_id": "14",
        "post_desc": "\ud83d\ude0e\ud83d\ude34\ud83d\ude01",
        "firstname": "Manish",
        "lastname": "Amin",
        "created_at": "2017-05-02 16:30:17",
        "files": []
    }, {
        "post_id": "13",
        "post_desc": "\ud83d\ude0e\ud83d\ude34\ud83d\ude01",
        "firstname": "Manish",
        "lastname": "Amin",
        "created_at": "2017-05-02 16:30:17",
        "files": []
    }, {
        "post_id": "12",
        "post_desc": "\ud83d\ude0e\ud83d\ude34\ud83d\ude01",
        "firstname": "Manish",
        "lastname": "Amin",
        "created_at": "2017-05-02 16:30:16",
        "files": []
    }, {
        "post_id": "11",
        "post_desc": "\ud83d\ude0e\ud83d\ude34\ud83d\ude01",
        "firstname": "Manish",
        "lastname": "Amin",
        "created_at": "2017-05-02 16:30:16",
        "files": []
    }, {
        "post_id": "10",
        "post_desc": "\ud83d\ude0a\ud83d\ude0a\ud83d\ude04\ud83d\ude04\u263a\ufe0f\ud83d\ude01\ud83d\ude01",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 16:30:14",
        "files": []
    }, {
        "post_id": "9",
        "post_desc": "Going to receive loads of money....",
        "firstname": "Manish",
        "lastname": "Amin",
        "created_at": "2017-05-02 16:08:58",
        "files": []
    }, {
        "post_id": "8",
        "post_desc": "\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 16:08:57",
        "files": []
    }, {
        "post_id": "7",
        "post_desc": "\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 16:08:55",
        "files": []
    }, {
        "post_id": "6",
        "post_desc": "\ud83d\ude02\ud83d\ude02\ud83d\ude02\ud83d\ude02",
        "firstname": "Abc",
        "lastname": "Xyz",
        "created_at": "2017-05-02 16:08:47",
        "files": []
    }, {
        "post_id": "5",
        "post_desc": "\ud83c\udfe1\ud83c\udfeb",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 16:05:40",
        "files": []
    }, {
        "post_id": "4",
        "post_desc": "\ud83d\udc4d\ud83d\udc4d\ud83d\ude0a\ud83d\ude12\ud83d\udc2e\ud83d\ude48\ud83d\ude1c\ud83d\ude09\ud83d\ude03",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 16:02:21",
        "files": []
    }, {
        "post_id": "3",
        "post_desc": "\ud83d\ude12\ud83d\ude0a",
        "firstname": "Rushin",
        "lastname": "Patel",
        "created_at": "2017-05-02 15:58:42",
        "files": []
    }, {
        "post_id": "2",
        "post_desc": "\ud83d\ude33\ud83d\ude33\ud83d\ude33",
        "firstname": "jaxi",
        "lastname": "chawda",
        "created_at": "2017-05-02 15:57:31",
        "files": []
    }, {
        "post_id": "1",
        "post_desc": "hii....good afternoon...\ud83d\ude04\ud83d\ude04\ud83d\ude04",
        "firstname": "jaxi",
        "lastname": "chawda",
        "created_at": "2017-05-02 15:55:49",
        "files": []
    }]
}

Here is my Android code:

   String filename = "";
            try {
                JSONObject jsonObject = new JSONObject(s);
                JSONArray posts = jsonObject.getJSONArray("posts");
                if(posts != null && posts.length() > 0 ) {
                    for (int i = 0; i < posts.length(); i++) {
                        JSONObject fileObj = posts.getJSONObject(i);

                        String fName = fileObj.getString("firstname");
                        String created_at = fileObj.getString("created_at");
                        String post_desc = fileObj.getString("post_desc");

                        Log.e("Details", fName + "" + created_at + "" + post_desc);

                        JSONArray files = fileObj.getJSONArray("files");
                        if(files != null && files.length() > 0 ) {

                            for (int j = 0; j < files.length(); j++) {
                                JSONObject Jsonfilename = files.getJSONObject(j);
                                filename = Jsonfilename.getString("file_name");
                                filename = "www.sample.com/home_webservice/compress/"+filename;
                                Log.e("Files", "" + filename);
                            }
                        }

                        Data_SAerver item = new Data_SAerver(fName,created_at,post_desc,filename);
                        data_sAervers.add(item);
                    }
                }

          adapter = new MyAdapter(data_sAervers,getApplicationContext());

                recyclerView.setAdapter(adapter);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            progressDialog.dismiss();

            Toast.makeText(getApplicationContext(), error.getMessage(),Toast.LENGTH_LONG).show();

        }
    });

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
}
}

DATA SERVER CLASS CODE

public class Data_SAerver {

    private String firstname;
    private  String created_at;
    private  String post_desc;

    private String filepath; /*= "http://cleanvadodara.esy.es/images/";*/

    public Data_SAerver(String firstname, String created_at, String post_desc,String filepath)
    { this.firstname = firstname;
        this.created_at = created_at;
        this.post_desc = post_desc;
        this.filepath = filepath;
    }
    public String getfilepath()
    { return filepath; }

    public Data_SAerver(String firstname, String created_at, String post_desc) {
        this.firstname = firstname;
        this.created_at = created_at;
        this.post_desc = post_desc;

    }

    public String getFirstname() {
        return firstname;
    }

    public String getCreated_at() {
        return created_at;
    }

    public String getPost_desc() {
        return post_desc;
    }

}

MY ADAPTER CLASS

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
    private List<Data_SAerver> data_sAervers;

    private Context context;
    public MyAdapter(List<Data_SAerver> data_sAervers, Context context) {
        this.data_sAervers = data_sAervers;
        this.context = context;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.sample, parent, false);
        return new ViewHolder(v);
    }
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        Data_SAerver data_sAerver = data_sAervers.get(position);
        holder.firstname.setText(data_sAerver.getFirstname());
        holder.created_at.setText(data_sAerver.getCreated_at());
        holder.post_desc.setText(data_sAerver.getPost_desc());
        Picasso.with(context).load(data_sAerver.getfilepath()).resize(736,1128).onlyScaleDown().into(holder.files);
   }

    @Override
    public int getItemCount() {
        return data_sAervers.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{

        public TextView firstname;
        public TextView created_at;
        public  TextView post_desc;
        public ImageView files;
        boolean isImageFitToScreen;

        public ViewHolder(View itemView) {
            super(itemView);

            firstname = (TextView) itemView.findViewById(R.id.firstname);
            created_at = (TextView) itemView.findViewById(R.id.created_at);
            post_desc= (TextView)itemView.findViewById(R.id.post_desc);
            files = (ImageView) itemView.findViewById(R.id.image_files);

         //   ImageViewPopUpHelper.enablePopUpOnClick(ViewHolder.this, files);

           /* files.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(isImageFitToScreen) {
                        isImageFitToScreen=true;
                        files.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
                        files.setAdjustViewBounds(true);
                    }else{
                        isImageFitToScreen=false;
                        files.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
                        files.setScaleType(ImageView.ScaleType.FIT_XY);
                    }
                }
            });*/

        }
    }

}

Please help to solve this error. Thank you.

Body:
This is my activity code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:cardview="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:padding="5dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="wrap_content">

            <android.support.v7.widget.CardView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:padding="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/iconone"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_marginBottom="5dp"
                    android:layout_marginLeft="5dp"
                    android:src="@drawable/logo" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/firstname"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:gravity="start"
                        android:text="Karan Brahmaxatriya"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textColor="#2196fe" />

                    <TextView

                        android:id="@+id/created_at"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:gravity="start"
                        android:text="23/05/2017  6:05 PM"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textColor="#333333"
                        android:textSize="16sp" />

                </LinearLayout>

            </LinearLayout>

            <ImageView
                android:id="@+id/image_files"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                 />
            <TextView
                android:id="@+id/filepathurl"
                android:visibility="gone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="filepathurl"/>
            <TextView
                android:id="@+id/playvideo"
                android:visibility="gone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="playvideo"/>
          <VideoView
              android:id="@+id/videoView"
              android:visibility="gone"
              android:layout_width="fill_parent"
              android:layout_height="190dp" />
            <TextView
                android:id="@+id/post_desc"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="start"
                android:layout_marginLeft="5dp"
                android:text="ccvvzv"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#333333" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1">

                <Button
                    android:id="@+id/comment_btn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Comment" />

                <Button
                    android:id="@+id/repost_btn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Repost" />

                <Button
                    android:id="@+id/like_btn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Like" />
            </LinearLayout>
        </LinearLayout>

    </android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>


来源: stackexchange

问:
FileNotFoundException when clicking on button to upload audio
I am uploading audio on soundcloud server but when i click upload button it throws FileNotFoundException.After uploading a response from server has to be generated.plss help me guys. please correct me if i am making mistake somewhere.

There are 2 situation in which upload function is performed.
1.Recording of only one page story audio and uloding it.(in this case the audio is being uploade).
2. Recording of more than one page story in which after uploading of 1st page audio the 2nd page will come as response from my server.(In this case its throwing FileNotFound Exception).

```<code>        upload.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String tag_string_req = "req_login";
                StringRequest postStringRequest = new StringRequest(Request.Method.POST, SC_LOGIN_LINK,
                        new Response.Listener<String>() {

                            @Override
                            public void onResponse(String response) {
                                Log.d(TAG,"Reponse Check for sound upload login :"+response);

                                // Log.d(TAG,"Object Check :"+json);
                                try {
                                    JSONObject json = new JSONObject(response);
                                    access_token = json.getString("access_token");
                                    expires_in = json.getString("expires_in");
                                    refresh_token = json.getString("refresh_token");
//                                doFileUpload();
                                    new AsyncTaskRunner().execute();
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        },
                        new Response.ErrorListener() {
                            @Override
                            public void onErrorResponse(VolleyError error) {
                                //Toast.makeText(AccessToken.this, error.toString(), Toast.LENGTH_LONG).show();
                                Log.e(TAG, "Error Response Check :" + error);

                            }
                        }){

                    @Override
                    protected Map<String, String> getParams() {
                        Map<String, String> params = new HashMap<String, String>();
                        params.put("client_id", client_id);
                        params.put("client_secret",client_secret);
                        params.put("grant_type",grant_type);
                        params.put("username",username);
                        params.put("password",user_password);
                        Log.d(TAG, "Params :" + params);
                        return params;

                    }

                };                    AppController.getInstance().addToRequestQueue(postStringRequest, tag_string_req);
            }
        });

    }
    private void mergeAudioFiles(){
        try {
            File tempFolder = new File(mRawAudioFolder.getPath());
            Movie[] movies = new Movie[tempFolder.listFiles().length];
            int i = 0;
            for (File saveTempFile : tempFolder.listFiles()) {
                try {
                    movies[i] = MovieCreator.build(new FileDataSourceImpl(saveTempFile));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                i++;
            }

            final Movie finalMovie = new Movie();

            List<Track> audioTracks = new ArrayList<>();
            for (Movie movie : movies) {
                for (Track track : movie.getTracks()) {
                }
            }
            finalMovie.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
            final Container container = new DefaultMp4Builder().build(finalMovie);
            mergedFile = new File(mAudioFolder.getPath()+"/merged.3gp");
            final FileOutputStream fos = new FileOutputStream(mergedFile);
            FileChannel fc = new RandomAccessFile(mergedFile, "rw").getChannel();
            container.writeContainer(fc);
            fc.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void createAudioFolder() {
        File movieFile = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);
        mRawAudioFolder = new File(movieFile, "Temp");
        mAudioFolder = new File(movieFile, "The Tagore Project");
        if (!mAudioFolder.exists()) {
            mAudioFolder.mkdirs();
        }
        if (!mRawAudioFolder.exists()) {
            mRawAudioFolder.mkdirs();
        }
    }
    public byte[] toByteArray(InputStream in) throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int read = 0;
        byte[] buffer = new byte[1024];
        while (read != -1) {
            read = in.read(buffer);
            if (read != -1)
                out.write(buffer,0,read);
        }
        out.close();
        return out.toByteArray();
    }

    public void forwardtoOurServer() {

        String tag_string_req = "req_login";
        StringRequest postStringRequest = new StringRequest(Request.Method.POST, RECORD_COMPOSITION_API,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        Log.d(TAG, "Audio Upload Response Check :" + response);

                        Log.d(TAG,"Object Check :"+response);
                        try {
                            JSONObject json = new JSONObject(response);
                            String code = json.getString("code");
                            if (String.valueOf(code).equals("200")) {

                                JSONObject upload = json.getJSONObject("upload");
                                JSONObject Booking = json.getJSONObject("upload").getJSONObject("Booking");
                                JSONObject Composition = json.getJSONObject("upload").getJSONObject("Composition");
                                JSONObject TableofContents = json.getJSONObject("upload").getJSONObject("TableOfContent");
                                String content = Composition.getString("content");
                                String pageno = Composition.getString("pageno");
                                String tocid = Composition.getString("table_of_content_id");
                                String wrd_count = Composition.getString("wordcount");
                                String tocName = TableofContents.getString("name");

                            } else {
                                String errorMsg = json.getString("error_msg");
                                Toast.makeText(getApplicationContext(),
                                        errorMsg, Toast.LENGTH_LONG).show();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.e(TAG, "Error Response Check :" + error);

                    }
                }) {

            @RequiresApi(api = Build.VERSION_CODES.N)
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();
                params.put("data[Booking][id]",bookingId);
                params.put("data[Booking][contributor_id]",contributor_id);
                params.put("data[Booking][table_of_content_id]",tocId);
                params.put("data[Booking][cdn_id]",vs_cdn_id);
                params.put("data[Booking][secret_token]",secret_token);
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
                sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
                Date now = new Date();
                String strDate = sdf.format(now);
                params.put("data[Booking][uploaded_on]",strDate);
                Log.d(TAG, "Params :" + params);
                return params;
            }

            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String, String> headers = new HashMap<String, String>();
                headers.put("Content-Type", "application/x-www-form-urlencoded");
                headers.put("UUID", device_uuid);
                headers.put("APPID", "2A192A0C22");
                headers.put("USERID", "1");
                headers.put("PLATFORM", "Andriod");
                headers.put("APP_REQUEST", "1");
                headers.put("PLATFORMVERSION",androidOS);
                return headers;
            }

        };

        AppController.getInstance().addToRequestQueue(postStringRequest, tag_string_req);

    }
    public void MediaRecorderReady(){
        mediaRecorder=new MediaRecorder();
        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
        mediaRecorder.setOutputFile(AudioSavePathInDevice);
    }

    public String CreateRandomAudioFileName(int string){
        StringBuilder stringBuilder = new StringBuilder( string );
        int i = 0 ;
        while(i < string ) {
            stringBuilder.append(RandomAudioFileName.
                    charAt(random.nextInt(RandomAudioFileName.length())));

            i++ ;
        }
        return stringBuilder.toString();
    }

    private void requestPermission() {
        ActivityCompat.requestPermissions(RecordComposition.this, new
                String[]{WRITE_EXTERNAL_STORAGE, RECORD_AUDIO}, RequestPermissionCode);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String permissions[], int[] grantResults) {
        switch (requestCode) {
            case RequestPermissionCode:
                if (grantResults.length> 0) {
                    boolean StoragePermission = grantResults[0] ==
                            PackageManager.PERMISSION_GRANTED;
                    boolean RecordPermission = grantResults[1] ==
                            PackageManager.PERMISSION_GRANTED;

                    if (StoragePermission && RecordPermission) {
                        Toast.makeText(RecordComposition.this, "Permission Granted",
                                Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(RecordComposition.this,"Permission Denied",Toast.LENGTH_LONG).show();
                    }
                }
                break;
        }
    }

    public boolean checkPermission() {
        int result = ContextCompat.checkSelfPermission(getApplicationContext(),
                WRITE_EXTERNAL_STORAGE);
        int result1 = ContextCompat.checkSelfPermission(getApplicationContext(),
                RECORD_AUDIO);
        return result == PackageManager.PERMISSION_GRANTED &&
                result1 == PackageManager.PERMISSION_GRANTED;
    }
    private class AsyncTaskRunner extends AsyncTask<String,Void,String> {
        @Override
        protected String doInBackground(String... params) {
            doFileUpload();
            return null;
        }
    }
    private void doFileUpload(){
        HttpURLConnection conn = null;
        //DataOutputStream dos = null;
        //DataInputStream inStream = null;
        String lineEnd = "\r\n";
        String twoHyphens = "--";
        String boundary =  "*****";
        int bytesRead, bytesAvailable, bufferSize;
        byte[] buffer;
        int maxBufferSize = 1*1024*1024;
        String responseFromServer = "";
        String urlString = "https://api.soundcloud.com/tracks";
        try
        {
            //------------------ CLIENT REQUEST
            FileInputStream fileInputStream = new FileInputStream(mergedFile);
            // open a URL connection to the Servlet
            URL url = new URL   (urlString);
            // Open a HTTP connection to the URL
            conn = (HttpURLConnection) url.openConnection();
            conn.setDoInput(true);
            conn.setDoOutput(true);

            conn.setUseCaches(false);

            conn.setRequestMethod("POST");
            conn.setRequestProperty("Connection", "Keep-Alive");
            conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
            DataOutputStream dos = new DataOutputStream( conn.getOutputStream() );
            //Adding oauth token
            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes("Content-Disposition: form-data; name=\"oauth_token\""+lineEnd+lineEnd+access_token+lineEnd);
//            dos.writeBytes(lineEnd);
            //Adding Track title
            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes("Content-Disposition: form-data; name=\"track[title]\""+lineEnd+lineEnd+tocName+"by Contributor"+":"+" "+contributorName+lineEnd);
            //Track taglist
            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes("Content-Disposition: form-data; name=\"track[tag_list]\""+lineEnd+lineEnd+"Tagore Project"+lineEnd);
            //Add sharing
            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes("Content-Disposition: form-data; name=\"track[sharing]\""+lineEnd+lineEnd+"private"+lineEnd);
            dos.writeBytes(lineEnd);

            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes("Content-Disposition: form-data; name=\"track[asset_data]\";filename=\"" + mergedFile + "\"" + lineEnd);
            dos.writeBytes("Content-Type: audio/mpeg"+lineEnd+lineEnd);
            // create a buffer of maximum size
            bytesAvailable = fileInputStream.available();
            bufferSize = Math.min(bytesAvailable, maxBufferSize);
            buffer = new byte[bufferSize];
            // read file and write it into form...
            bytesRead = fileInputStream.read(buffer, 0, bufferSize);

            while (bytesRead > 0)
            {
                dos.write(buffer, 0, bufferSize);
                bytesAvailable = fileInputStream.available();
                bufferSize = Math.min(bytesAvailable, maxBufferSize);
                bytesRead = fileInputStream.read(buffer, 0, bufferSize);
            }

            dos.writeBytes(lineEnd+twoHyphens + boundary + twoHyphens + lineEnd);
            fileInputStream.close();
            dos.flush();
            dos.close();
            Log.e("Debug","File is written - "+mergedFile+" - "+conn.getResponseCode());
        }
        catch (MalformedURLException ex)
        {
            Log.e("Debug", "error: " + ex.getMessage(), ex);
            Toast.makeText(this, ex.getMessage(), Toast.LENGTH_SHORT).show();
        }
        catch (IOException ioe)
        {
            Log.e("Debug", "error: " + ioe.getMessage(), ioe);
            Toast.makeText(this, ioe.getMessage(), Toast.LENGTH_SHORT).show();
        }
        try {
            BufferedReader inStream = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String str;
            Log.e("Debug","Before while");
            while (( str = inStream.readLine()  ) != null)
            {
                Log.e("Debug","Server Response "+str);
                JSONObject response = new JSONObject(str);
                vs_cdn_id = response.getString("id");
                secret_token = response.getString("secret_token");
                forwardtoOurServer();
            }
            inStream.close();
        }
        catch (IOException ioex){
            Log.e("Debug", "error: " + ioex.getMessage(), ioex);
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (Exception ex){
            ex.printStackTrace();
        }
    }
</code>```

Log:

```<code>File is written - /storage/emulated/0/Movies/The Tagore Project/merged.3gp - 500
      error: https://api.soundcloud.com/tracks
                                                                                java.io.FileNotFoundException: https://api.soundcloud.com/tracks
                                                                                at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:238)
                                                                                at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
                                                                                at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java)
                                                                                at com.showhow2.www.thetagoreproject.RecordComposition.doFileUpload(RecordComposition.java:923)
                                                                                at com.showhow2.www.thetagoreproject.RecordComposition.access$2400(RecordComposition.java:73)
                                                                                at com.showhow2.www.thetagoreproject.RecordComposition$AsyncTaskRunner.doInBackground(RecordComposition.java:829)
                                                                                at com.showhow2.www.thetagoreproject.RecordComposition$AsyncTaskRunner.doInBackground(RecordComposition.java:824)
                                                                                at android.os.AsyncTask$2.call(AsyncTask.java:295)
                                                                                at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
                                                                                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                                at java.lang.Thread.run(Thread.java:818)
</code>```

答:
Give permission in menifest...</p>

```<code>   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
   <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I am uploading audio on soundcloud server but when i click upload button it throws FileNotFoundException.After uploading a response from server has to be generated.plss help me guys. please correct me if i am making mistake somewhere.

There are 2 situation in which upload function is performed.
1.Recording of only one page story audio and uloding it.(in this case the audio is being uploade).
2. Recording of more than one page story in which after uploading of 1st page audio the 2nd page will come as response from my server.(In this case its throwing FileNotFound Exception).

        upload.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String tag_string_req = "req_login";
                StringRequest postStringRequest = new StringRequest(Request.Method.POST, SC_LOGIN_LINK,
                        new Response.Listener<String>() {

                            @Override
                            public void onResponse(String response) {
                                Log.d(TAG,"Reponse Check for sound upload login :"+response);

                                // Log.d(TAG,"Object Check :"+json);
                                try {
                                    JSONObject json = new JSONObject(response);
                                    access_token = json.getString("access_token");
                                    expires_in = json.getString("expires_in");
                                    refresh_token = json.getString("refresh_token");
//                                doFileUpload();
                                    new AsyncTaskRunner().execute();
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        },
                        new Response.ErrorListener() {
                            @Override
                            public void onErrorResponse(VolleyError error) {
                                //Toast.makeText(AccessToken.this, error.toString(), Toast.LENGTH_LONG).show();
                                Log.e(TAG, "Error Response Check :" + error);

                            }
                        }){

                    @Override
                    protected Map<String, String> getParams() {
                        Map<String, String> params = new HashMap<String, String>();
                        params.put("client_id", client_id);
                        params.put("client_secret",client_secret);
                        params.put("grant_type",grant_type);
                        params.put("username",username);
                        params.put("password",user_password);
                        Log.d(TAG, "Params :" + params);
                        return params;

                    }

                };                    AppController.getInstance().addToRequestQueue(postStringRequest, tag_string_req);
            }
        });

    }
    private void mergeAudioFiles(){
        try {
            File tempFolder = new File(mRawAudioFolder.getPath());
            Movie[] movies = new Movie[tempFolder.listFiles().length];
            int i = 0;
            for (File saveTempFile : tempFolder.listFiles()) {
                try {
                    movies[i] = MovieCreator.build(new FileDataSourceImpl(saveTempFile));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                i++;
            }

            final Movie finalMovie = new Movie();

            List<Track> audioTracks = new ArrayList<>();
            for (Movie movie : movies) {
                for (Track track : movie.getTracks()) {
                }
            }
            finalMovie.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
            final Container container = new DefaultMp4Builder().build(finalMovie);
            mergedFile = new File(mAudioFolder.getPath()+"/merged.3gp");
            final FileOutputStream fos = new FileOutputStream(mergedFile);
            FileChannel fc = new RandomAccessFile(mergedFile, "rw").getChannel();
            container.writeContainer(fc);
            fc.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void createAudioFolder() {
        File movieFile = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);
        mRawAudioFolder = new File(movieFile, "Temp");
        mAudioFolder = new File(movieFile, "The Tagore Project");
        if (!mAudioFolder.exists()) {
            mAudioFolder.mkdirs();
        }
        if (!mRawAudioFolder.exists()) {
            mRawAudioFolder.mkdirs();
        }
    }
    public byte[] toByteArray(InputStream in) throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int read = 0;
        byte[] buffer = new byte[1024];
        while (read != -1) {
            read = in.read(buffer);
            if (read != -1)
                out.write(buffer,0,read);
        }
        out.close();
        return out.toByteArray();
    }

    public void forwardtoOurServer() {

        String tag_string_req = "req_login";
        StringRequest postStringRequest = new StringRequest(Request.Method.POST, RECORD_COMPOSITION_API,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        Log.d(TAG, "Audio Upload Response Check :" + response);

                        Log.d(TAG,"Object Check :"+response);
                        try {
                            JSONObject json = new JSONObject(response);
                            String code = json.getString("code");
                            if (String.valueOf(code).equals("200")) {

                                JSONObject upload = json.getJSONObject("upload");
                                JSONObject Booking = json.getJSONObject("upload").getJSONObject("Booking");
                                JSONObject Composition = json.getJSONObject("upload").getJSONObject("Composition");
                                JSONObject TableofContents = json.getJSONObject("upload").getJSONObject("TableOfContent");
                                String content = Composition.getString("content");
                                String pageno = Composition.getString("pageno");
                                String tocid = Composition.getString("table_of_content_id");
                                String wrd_count = Composition.getString("wordcount");
                                String tocName = TableofContents.getString("name");

                            } else {
                                String errorMsg = json.getString("error_msg");
                                Toast.makeText(getApplicationContext(),
                                        errorMsg, Toast.LENGTH_LONG).show();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.e(TAG, "Error Response Check :" + error);

                    }
                }) {

            @RequiresApi(api = Build.VERSION_CODES.N)
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();
                params.put("data[Booking][id]",bookingId);
                params.put("data[Booking][contributor_id]",contributor_id);
                params.put("data[Booking][table_of_content_id]",tocId);
                params.put("data[Booking][cdn_id]",vs_cdn_id);
                params.put("data[Booking][secret_token]",secret_token);
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
                sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
                Date now = new Date();
                String strDate = sdf.format(now);
                params.put("data[Booking][uploaded_on]",strDate);
                Log.d(TAG, "Params :" + params);
                return params;
            }

            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String, String> headers = new HashMap<String, String>();
                headers.put("Content-Type", "application/x-www-form-urlencoded");
                headers.put("UUID", device_uuid);
                headers.put("APPID", "2A192A0C22");
                headers.put("USERID", "1");
                headers.put("PLATFORM", "Andriod");
                headers.put("APP_REQUEST", "1");
                headers.put("PLATFORMVERSION",androidOS);
                return headers;
            }

        };

        AppController.getInstance().addToRequestQueue(postStringRequest, tag_string_req);

    }
    public void MediaRecorderReady(){
        mediaRecorder=new MediaRecorder();
        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
        mediaRecorder.setOutputFile(AudioSavePathInDevice);
    }

    public String CreateRandomAudioFileName(int string){
        StringBuilder stringBuilder = new StringBuilder( string );
        int i = 0 ;
        while(i < string ) {
            stringBuilder.append(RandomAudioFileName.
                    charAt(random.nextInt(RandomAudioFileName.length())));

            i++ ;
        }
        return stringBuilder.toString();
    }

    private void requestPermission() {
        ActivityCompat.requestPermissions(RecordComposition.this, new
                String[]{WRITE_EXTERNAL_STORAGE, RECORD_AUDIO}, RequestPermissionCode);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String permissions[], int[] grantResults) {
        switch (requestCode) {
            case RequestPermissionCode:
                if (grantResults.length> 0) {
                    boolean StoragePermission = grantResults[0] ==
                            PackageManager.PERMISSION_GRANTED;
                    boolean RecordPermission = grantResults[1] ==
                            PackageManager.PERMISSION_GRANTED;

                    if (StoragePermission && RecordPermission) {
                        Toast.makeText(RecordComposition.this, "Permission Granted",
                                Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(RecordComposition.this,"Permission Denied",Toast.LENGTH_LONG).show();
                    }
                }
                break;
        }
    }

    public boolean checkPermission() {
        int result = ContextCompat.checkSelfPermission(getApplicationContext(),
                WRITE_EXTERNAL_STORAGE);
        int result1 = ContextCompat.checkSelfPermission(getApplicationContext(),
                RECORD_AUDIO);
        return result == PackageManager.PERMISSION_GRANTED &&
                result1 == PackageManager.PERMISSION_GRANTED;
    }
    private class AsyncTaskRunner extends AsyncTask<String,Void,String> {
        @Override
        protected String doInBackground(String... params) {
            doFileUpload();
            return null;
        }
    }
    private void doFileUpload(){
        HttpURLConnection conn = null;
        //DataOutputStream dos = null;
        //DataInputStream inStream = null;
        String lineEnd = "\r\n";
        String twoHyphens = "--";
        String boundary =  "*****";
        int bytesRead, bytesAvailable, bufferSize;
        byte[] buffer;
        int maxBufferSize = 1*1024*1024;
        String responseFromServer = "";
        String urlString = "https://api.soundcloud.com/tracks";
        try
        {
            //------------------ CLIENT REQUEST
            FileInputStream fileInputStream = new FileInputStream(mergedFile);
            // open a URL connection to the Servlet
            URL url = new URL   (urlString);
            // Open a HTTP connection to the URL
            conn = (HttpURLConnection) url.openConnection();
            conn.setDoInput(true);
            conn.setDoOutput(true);

            conn.setUseCaches(false);

            conn.setRequestMethod("POST");
            conn.setRequestProperty("Connection", "Keep-Alive");
            conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
            DataOutputStream dos = new DataOutputStream( conn.getOutputStream() );
            //Adding oauth token
            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes("Content-Disposition: form-data; name=\"oauth_token\""+lineEnd+lineEnd+access_token+lineEnd);
//            dos.writeBytes(lineEnd);
            //Adding Track title
            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes("Content-Disposition: form-data; name=\"track[title]\""+lineEnd+lineEnd+tocName+"by Contributor"+":"+" "+contributorName+lineEnd);
            //Track taglist
            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes("Content-Disposition: form-data; name=\"track[tag_list]\""+lineEnd+lineEnd+"Tagore Project"+lineEnd);
            //Add sharing
            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes("Content-Disposition: form-data; name=\"track[sharing]\""+lineEnd+lineEnd+"private"+lineEnd);
            dos.writeBytes(lineEnd);

            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes("Content-Disposition: form-data; name=\"track[asset_data]\";filename=\"" + mergedFile + "\"" + lineEnd);
            dos.writeBytes("Content-Type: audio/mpeg"+lineEnd+lineEnd);
            // create a buffer of maximum size
            bytesAvailable = fileInputStream.available();
            bufferSize = Math.min(bytesAvailable, maxBufferSize);
            buffer = new byte[bufferSize];
            // read file and write it into form...
            bytesRead = fileInputStream.read(buffer, 0, bufferSize);

            while (bytesRead > 0)
            {
                dos.write(buffer, 0, bufferSize);
                bytesAvailable = fileInputStream.available();
                bufferSize = Math.min(bytesAvailable, maxBufferSize);
                bytesRead = fileInputStream.read(buffer, 0, bufferSize);
            }

            dos.writeBytes(lineEnd+twoHyphens + boundary + twoHyphens + lineEnd);
            fileInputStream.close();
            dos.flush();
            dos.close();
            Log.e("Debug","File is written - "+mergedFile+" - "+conn.getResponseCode());
        }
        catch (MalformedURLException ex)
        {
            Log.e("Debug", "error: " + ex.getMessage(), ex);
            Toast.makeText(this, ex.getMessage(), Toast.LENGTH_SHORT).show();
        }
        catch (IOException ioe)
        {
            Log.e("Debug", "error: " + ioe.getMessage(), ioe);
            Toast.makeText(this, ioe.getMessage(), Toast.LENGTH_SHORT).show();
        }
        try {
            BufferedReader inStream = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String str;
            Log.e("Debug","Before while");
            while (( str = inStream.readLine()  ) != null)
            {
                Log.e("Debug","Server Response "+str);
                JSONObject response = new JSONObject(str);
                vs_cdn_id = response.getString("id");
                secret_token = response.getString("secret_token");
                forwardtoOurServer();
            }
            inStream.close();
        }
        catch (IOException ioex){
            Log.e("Debug", "error: " + ioex.getMessage(), ioex);
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (Exception ex){
            ex.printStackTrace();
        }
    }

Log:

File is written - /storage/emulated/0/Movies/The Tagore Project/merged.3gp - 500
      error: https://api.soundcloud.com/tracks
                                                                                java.io.FileNotFoundException: https://api.soundcloud.com/tracks
                                                                                at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:238)
                                                                                at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
                                                                                at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java)
                                                                                at com.showhow2.www.thetagoreproject.RecordComposition.doFileUpload(RecordComposition.java:923)
                                                                                at com.showhow2.www.thetagoreproject.RecordComposition.access$2400(RecordComposition.java:73)
                                                                                at com.showhow2.www.thetagoreproject.RecordComposition$AsyncTaskRunner.doInBackground(RecordComposition.java:829)
                                                                                at com.showhow2.www.thetagoreproject.RecordComposition$AsyncTaskRunner.doInBackground(RecordComposition.java:824)
                                                                                at android.os.AsyncTask$2.call(AsyncTask.java:295)
                                                                                at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
                                                                                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                                at java.lang.Thread.run(Thread.java:818)

Body:
Give permission in menifest...

   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
   <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />


问:
alter view in SQL DB2, adding new column
I have created a view orderedView by ordering by series and values looking like this:

```<code>series | values
     1 | 1
     1 | 3
     1 | 5
     1 | 6
     2 | -1
     2 | 0
     2 | 4
     2 | 5
</code>```

Now I would like to add a third column to my view, that enumerates each set of series from 1 to the end, like

```<code>series | values  | row_ID
     1 |    1    | 1
     1 |    3    | 2
     1 |    5    | 3
     1 |    6    | 4
     2 |    3    | 1
     2 |    6    | 2
     2 |    8    | 3
     2 |    9    | 4
</code>```

I tried with

```<code>ALTER VIEW orderedView
    ADD COLUMN ROW_ID INT NOT NULL;
</code>```

but intelliJ says after ALTER VIEW orderedView  "ALTER, DISABLE or ENABLE expected, got 'ADD'"

Is it even possible to alter my view by adding a new column or do I have to add the column before creating the view? And if so, how to do that?

Thanks in advance for any help.

答: You must drop and recreate your view. A view is a query, your must then modified this query...</p>

Body:
I have created a view orderedView by ordering by series and values looking like this:

series | values
     1 | 1
     1 | 3
     1 | 5
     1 | 6
     2 | -1
     2 | 0
     2 | 4
     2 | 5

Now I would like to add a third column to my view, that enumerates each set of series from 1 to the end, like

series | values  | row_ID
     1 |    1    | 1
     1 |    3    | 2
     1 |    5    | 3
     1 |    6    | 4
     2 |    3    | 1
     2 |    6    | 2
     2 |    8    | 3
     2 |    9    | 4

I tried with

ALTER VIEW orderedView
    ADD COLUMN ROW_ID INT NOT NULL;

but intelliJ says after ALTER VIEW orderedView  "ALTER, DISABLE or ENABLE expected, got 'ADD'"

Is it even possible to alter my view by adding a new column or do I have to add the column before creating the view? And if so, how to do that?

Thanks in advance for any help.


问:
BizTalk BAM Browser - Column Chooser - works on Win 7 but not BizTalk Server (Win 2012/R2)
My laptop is Windows 7 with IE 11.0.9600.18665 and when I access the BAM portal everything works fine.

BizTalk 2016 is installed on Win 2012/R2, with IE 11.0.9600.18666.  But on the Win 2012 server, when I click "Activity Search", select an activity, and then use the "Column Chooser" and click the ">>" button to move the field from the left to the right, nothing happens.

I'm logged on with the same credentials on each. Why would have this issue on the server?

答:
Add your localhost to compatibility view of internet explorer.

For more info:
https://en.wikipedia.org/wiki/Compatibility_mode

How to change it:

Localhost (current site) will show in top box, then click "Add" and it moves to lower box:


问:
PHP open pdf and redirect with header
I'm using fpdf for create a pdf, this works correctly, the problem is, I need to use header to redirect in determined php file, but doesn't work.

```<code> //Report.php
 //data in pdf created correctly.
 $pdf->close();
 //without ob_end_clean, the pdf doesn't show
 ob_end_clean();
 $pdf->Output($file,'I');
 //return to index.php
 header("Location: ".DOL_URL_ROOT.'/product/stock/index.php');
</code>```

Hi, what I need is:

1 Create and fill pdf, DONE.

2 Display or download pdf, DONE

3 Redirect to antoher page, PENDING, this is the part is not working.

Thanks

答:
Just remove the header call.
pdf->output($file,'I') will anyhow display the newly created file.</p>

Title: PHP open pdf and redirect with header

Body:
I'm using fpdf for create a pdf, this works correctly, the problem is, I need to use header to redirect in determined php file, but doesn't work.

 //Report.php
 //data in pdf created correctly.
 $pdf->close();
 //without ob_end_clean, the pdf doesn't show
 ob_end_clean();
 $pdf->Output($file,'I');
 //return to index.php
 header("Location: ".DOL_URL_ROOT.'/product/stock/index.php');

Hi, what I need is:

1 Create and fill pdf, DONE.

2 Display or download pdf, DONE

3 Redirect to antoher page, PENDING, this is the part is not working.

Thanks


问:
Loading Page Fragments with .load() excludes embeded javascript
I have a form that is loaded using the .load() method.

```<code>$(function() {
    $('#items,#button-search').hide();
    $("#companies").click(function() {
        $(this).attr("value","");
        $('#address,#new-company-form').empty();
    });
    $( "#companies" ).autocomplete({
        source: ";companies",
        minLength: 2,
        select: function( event, ui ) {
            if(ui.item.id == "create-new-company") {
                // call the new company form
                $('#address').empty();
                $('#new-company-form').load(';company_form #autoform');
            }
            else
            {
                $('#new-company-form').empty();
                $.ajax({
                    type: 'GET',
                    url: ';addresses?company=' + ui.item.id,
                    dataType: 'json',
                    // process the addresses
                    success: function(json) {
                        var opts = '';
                        $.each(json, function(k, v) {
                            opts += '<option>' + v + '</option>';
                        });
                        $('#address').html('<select>' + opts + '</select>');
                    }
                }); //end ajax call to address
            }
        } // end select address
    }); // end autocomplete
}); // end function
</code>```

on line 15, i have

```<code>$('#new-company-form').load(';company_form #autoform');
</code>```

if i remove the #autoform the javascript that is in the ;company_form html works, otherwise it is not loaded.

how do i get this to work?

thanks

答:
The first parameter of the .load() method is the url. The url that you need here is probably just ;company_form. What do you want to achieve by passing #autoform in the url?

If it works without the #autoform, then why don't you simply remove it?

ContentLicense: CC BY-SA 2.5

Body:
I have a form that is loaded using the .load() method.

$(function() {
    $('#items,#button-search').hide();
    $("#companies").click(function() {
        $(this).attr("value","");
        $('#address,#new-company-form').empty();
    });
    $( "#companies" ).autocomplete({
        source: ";companies",
        minLength: 2,
        select: function( event, ui ) {
            if(ui.item.id == "create-new-company") {
                // call the new company form
                $('#address').empty();
                $('#new-company-form').load(';company_form #autoform');
            }
            else
            {
                $('#new-company-form').empty();
                $.ajax({
                    type: 'GET',
                    url: ';addresses?company=' + ui.item.id,
                    dataType: 'json',
                    // process the addresses
                    success: function(json) {
                        var opts = '';
                        $.each(json, function(k, v) {
                            opts += '<option>' + v + '</option>';
                        });
                        $('#address').html('<select>' + opts + '</select>');
                    }
                }); //end ajax call to address
            }
        } // end select address
    }); // end autocomplete
}); // end function

on line 15, i have

$('#new-company-form').load(';company_form #autoform');

if i remove the #autoform the javascript that is in the ;company_form html works, otherwise it is not loaded.

how do i get this to work?

thanks