Hi I am very new for android and in my app I am parsing Json obejct using Gson and I am displaying result in listView for this I used below code but I am getting exception like
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2
please help me some one
json response:-
 {
    "Header": {
        "CutQuantity": 0,
        "ETAQuantity": 0,
        "IDRPrice": 229000,
        "MasterId": 65639,
        "Name": "VENICE SATIN DBY 21491 COL 25894",
        "POQuantity": 0,
        "ProductCode": "GG01054-14B",
        "QtyOnHand": 332.1,
        "ReservedQuantity": "332.1",
        "SellingPrice": 229000,
        "TotalAvlQuantity": 0,
        "USDPrice": 26
    },
    "Batches": [{
        "AvailableQty": 25.8,
        "BatchNo": "A001",
        "BinId": 128430,
        "BinName": "Dummy-700",
        "DeptId": 23,
        "DeptName": "G.700",
        "MaxBodyId": 128430,
        "ProductCode": "GG01054-14B",
        "ProductCodeBatch": "GG01054-14B-A001",
        "ProductId": 65639,
        "ProductName": "VENICE SATIN DBY 21491 COL 25894"
    }, {
        "AvailableQty": 40,
        "BatchNo": "A002",
        "BinId": 128433,
        "BinName": "Dummy-700",
        "DeptId": 23,
        "DeptName": "G.700",
        "MaxBodyId": 128433,
        "ProductCode": "GG01054-14B",
        "ProductCodeBatch": "GG01054-14B-A002",
        "ProductId": 65639,
        "ProductName": "VENICE SATIN DBY 21491 COL 25894"
    }]
}
MainActivity:-
 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_layout);
        getAllTips(); //Getting friendArrayList data from Services
    }
       private void getAllTips() {
        try {
            JSONObject json = new JSONObject();
            json.put("scancode", "GG01054-14B");
            if (CommonUtilities.isNetWorkStateAvailble(MainActivity.this)) {
                AsyncTaskClass task = new AsyncTaskClass(this, MainActivity.this,
                        json);
                task.execute(ServiceUrl.GET_STOCKDETAILS_ID_URL, "1",
                        "");
            } else {
                Log.d("==========>", "There is Network Error");
            }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    @Override
    public void doPostExecute(StatusObject statusObject) {
        // TODO Auto-generated method stub
        if (statusObject != null) {
            if (statusObject.getResponseCode() == 401) {
                Log.d("==========>", "Session Has been Expired");
            } else if (statusObject.getResponseCode() == 200) {
                handleResponseData(statusObject.getMessage());
            } else {
                Log.d("==========>", "Server not responding. Please try again later.");
            }
        } else {
            Log.d("==========>", "Server not responding. Please try again later.");
        }
    }
    // handle the response
    private void handleResponseData(String result) {
        Log.d("Final is==========>", result);
        if (result != null) {
            try {
                JSONObject json = new JSONObject(result);
                if (json.has("Header")) {
                    if (json.getString("Header").equalsIgnoreCase("null")
                            || json.getString("Header") == null) {
                        CommonUtilities
                                .showToastMessage(MainActivity.this,
                                        "Product Information unavailable with this Barcode");
                    } else {
                        System.out.println("your here");
                        handleTripsResponse(result);
                    }
                } else if (json.has("error")) {
                    if (json.has("message")) {
                        CommonUtilities.showToastMessage(MainActivity.this,
                                "" + json.getString("message"));
                    }
                }
            } catch (JSONException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        } else {
            CommonUtilities.showToastMessage(MainActivity.this,
                    "Product Information unavailable with this Barcode");
        }
    }
        private void handleTripsResponse(String result) {
            try {
              Type type = new TypeToken<Response>() {
            }.getType();
            GsonBuilder gsonBuilder = new GsonBuilder();
            gsonBuilder.setDateFormat("M/d/yy hh:mm a");
            Gson gson = gsonBuilder.create();
            Response post = gson.fromJson(result,type);
            friendArrayList.add(post);
                int listSize = friendArrayList.size();
                if (friendArrayList.size() != 0) {
                     listView = (ListView) findViewById(R.id.list);
                     adapter = new CustomListViewAdapter(MainActivity.this,
                             R.layout.list_item, friendArrayList);
                     listView.setAdapter(adapter);
                }else{
                    Log.d("=======>" ,"No data Available");
                }
            } catch (Throwable throwable) {
                System.out.println("Exception is " + throwable);
            }
    }
CustomListViewAdapter:-
public class CustomListViewAdapter extends ArrayAdapter<Response> {
    LayoutInflater inflater;
    Context context;
    ArrayList<Response> coridersList = new ArrayList<Response>();
    public CustomListViewAdapter(Activity context, int resourceId,
                                 ArrayList<Response> items) {
        super(context,resourceId, items);
        this.context = context;
        inflater = context.getLayoutInflater();
        this.coridersList = items;
    }
    @Override
    public View getView(final int position, View view, ViewGroup parent) {
        Response rowItem = getItem(position);
        View rowView= inflater.inflate(R.layout.list_item, null, true);
        TextView txtTitle = (TextView) rowView.findViewById(R.id.title);
        txtTitle.setText(rowItem.getHeader().getAlerts().getDeptName());
        TextView desc = (TextView) rowView.findViewById(R.id.desc);
        desc.setText(rowItem.getHeader().getAlerts().getProductCode());
       // ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
       // imageView.setImageResource(rowItem.getImageId());
        return rowView;
    }
}
Response:-
public class Response {
    private Header header;
    public Header getHeader(){
        return header;
    }
    public void setHeader(Header header){
        this.header = header;
    }
}
Header:-
public class Header {
    private TerritoryBean alerts;
    private String Name;
    private String ProductCode;
    private int MasterId;
    private int SellingPrice;
    private int IDRPrice;
    private int USDPrice;
    private int POQuantity;
    private int ReservedQuantity;
    private float ETAQuantity;
    private float CutQuantity;
    private float TotalAvlQuantity;
    private float QtyOnHand;
    public TerritoryBean getAlerts(){
        return alerts;
    }
    public void setAlerts(TerritoryBean alerts){
        this.alerts = alerts;
    }
    public String getName(){
        return Name;
    }
    public void setName(String Name){
        this.Name = Name;
    }
    public String getProductCode(){
        return ProductCode;
    }
    public void setProductCode(String ProductCode){
        this.ProductCode = ProductCode;
    }
}
TerritoryBean:-
public class TerritoryBean {
    private int DeptId;
    private String DeptName;
    private int ProductId;
    private String ProductCode;
    private String ProductName;
    private String BatchNo;
    private String ProductCodeBatch;
    private int MaxBodyId;
    private float AvailableQty;
    private String BinId;
    private String BinName;
    public int getDeptId(){
        return DeptId;
    }
    public void setDeptId(int DeptId){
        this.DeptId = DeptId;
    }
    public String getDeptName(){
        return DeptName;
    }
    public void setDeptName(String DeptName){
        this.DeptName = DeptName;
    }
    public int getProductId(){
        return ProductId;
    }
    public void setProductId(int ProductId){
        this.ProductId = ProductId;
    }
    public String getProductCode(){
        return ProductCode;
    }
    public void setProductCode(String ProductCode){
        this.ProductCode = ProductCode;
    }
    public String getProductName(){
        return ProductName;
    }
    public void setProductName(String ProductName){
        this.ProductName = ProductName;
    }
}
 
     
     
    