android – How to parse this JSON and retrieve data in the mainactivity and set it to recyclerview-ThrowExceptions

Exception or error:
"data": [
        "0": [
                    "fans_id": "2",
                    "ans": "ans",
                    "qst_id": "15",
                    "ans_uid": "20",
                    "ans_date": "2017-09-05 22:13:58"
                    "fans_id": "3",
                    "ans": "8770577495",
                    "qst_id": "15",
                    "ans_uid": "20",
                    "ans_date": "2017-09-09 03:23:51"
        "forum_id": "15",
        "qst": "cxvcxv",
        "qst_description": "xcvcx\n",
        "qst_uid": "20",
        "q_status": "Enable",
        "user_id": "20",
        "univer_id": "1",
        "fullname": "Deepak Verma",
        "branchid": "10",
        "semid": "1",
        "collegeid": "1",
        "mobile": "9685318196",
        "bio": "",
        "enrollno": "",
        "username": "",
        "password": "e10adc3949ba59abbe56e057f20f883e",
        "u_status": "Enable",
        "user_image": "user.png",
        "loginwith": "",
        "otp": ""


This is my JSON data ,how could I parse it and set this data to the adapter so that it works fine and run on recycler view. The problem mainly occurs in the adapter part is not able to set two different data list, I am making it using two model class one parent model and second child model

This is my Adapter code

public class Adapter_theory extends RecyclerView.Adapter<Adapter_theory.Viewholder> {
private Context context;
private LayoutInflater inflater;
List<Model_theory> listtheorydata= Collections.emptyList();
Model_theory current;
int currentPos=0;
Intent intent;

public Adapter_theory(Context context, List<Model_theory> listtheorydata) {
    this.context = context;
    this.listtheorydata = listtheorydata;
    inflater= LayoutInflater.from(context);


public Adapter_theory.Viewholder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view=inflater.inflate(R.layout.view_theory, parent,false);
    Viewholder holder=new Viewholder(view);
    return holder;

public void onBindViewHolder(Adapter_theory.Viewholder holder, final int position) {
    final Viewholder theoryholder = (Viewholder) holder;
    Model_theory  current = listtheorydata.get(position);
    final String title = Html.fromHtml(current.mt_tittle).toString();
    final String theory = Html.fromHtml(current.myheory).toString();
    final String image = Html.fromHtml(current.myheory + "<img src=\"").toString();
    final String secondimage = current.getMyimages();

    theoryholder.btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {


    theoryholder.itemView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Model_theory current = listtheorydata.get(position);
            intent = new Intent(context,TheoryDetailActivity.class);


public int getItemCount() {
    return listtheorydata.size() ;

public class Viewholder extends RecyclerView.ViewHolder {
    TextView theorytittle;
    PlayPauseView btn;
    public Viewholder(View itemView) {
        theorytittle = (TextView)itemView.findViewById(;
        btn = (PlayPauseView)itemView.findViewById(;
How to solve:

I would suggest you to create a model class for this json and then using gson library to parse it into model, then you can use that model in recyclerview easily.

you can add gson library by downloading the jar file from the link shown below:

Leave a Reply

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