androidandroid-recyclerviewandroid-databindingandroid-query

java.lang.IllegalArgumentException: the bind value at index 2 is null?


I'm getting this error and the app crashes after reaching the end of the recyclerView list.I dunno why it is happening. I am new to recyclerView and Database. I have no idea what it is.

Logcat

java.lang.IllegalArgumentException: the bind value at index 2 is null
        at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:167)
        at android.database.sqlite.SQLiteProgram.bindAllArgsAsStrings(SQLiteProgram.java:203)
        at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:49)
        at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1443)
        at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1290)
        at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1161)
        at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1367)
------->at com.disha.daily_fresh.DataBase.DatabaseHelper.getCard(DatabaseHelper.java:80)
------->at com.disha.daily_fresh.Adepter.ItemAdp.setJoinPlayrList(ItemAdp.java:189)
------->at com.disha.daily_fresh.Adepter.ItemAdp.onBindViewHolder(ItemAdp.java:110)
------->at com.disha.daily_fresh.Adepter.ItemAdp.onBindViewHolder(ItemAdp.java:45)
        at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:7065)
        at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7107)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6012)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6279)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
        at androidx.recyclerview.widget.LayoutState.next(LayoutState.java:98)
        at androidx.recyclerview.widget.StaggeredGridLayoutManager.fill(StaggeredGridLayoutManager.java:1607)
        at androidx.recyclerview.widget.StaggeredGridLayoutManager.scrollBy(StaggeredGridLayoutManager.java:2180)
        at androidx.recyclerview.widget.StaggeredGridLayoutManager.scrollVerticallyBy(StaggeredGridLayoutManager.java:2039)
        at androidx.recyclerview.widget.RecyclerView.scrollStep(RecyclerView.java:1841)
        at androidx.recyclerview.widget.RecyclerView.scrollByInternal(RecyclerView.java:1940)
        at androidx.recyclerview.widget.RecyclerView.onGenericMotionEvent(RecyclerView.java:3501)
        at android.view.View.dispatchGenericMotionEventInternal(View.java:14092)
        at android.view.View.dispatchGenericMotionEvent(View.java:14073)
        at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2551)
        at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:2508)
        at android.view.View.dispatchGenericMotionEvent(View.java:14066)
        at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2551)
        at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:2508)
        at android.view.View.dispatchGenericMotionEvent(View.java:14066)
        at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2551)
        at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:2508)
        at android.view.View.dispatchGenericMotionEvent(View.java:14066)
        at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2551)
        at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:2508)
        at android.view.View.dispatchGenericMotionEvent(View.java:14066)
        at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2551)
        at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:2508)
        at android.view.View.dispatchGenericMotionEvent(View.java:14066)
        at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2551)
        at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:2508)
        at android.view.View.dispatchGenericMotionEvent(View.java:14066)
        at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2551)
        at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:2508)
2020-08-07 21:09:07.653 7068-7068/com.disha.daily_fresh E/AndroidRuntime:     at android.view.View.dispatchGenericMotionEvent(View.java:14066)
        at androidx.drawerlayout.widget.DrawerLayout.dispatchGenericMotionEvent(DrawerLayout.java:1539)
        at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2551)
        at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:2508)
        at android.view.View.dispatchGenericMotionEvent(View.java:14066)
        at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2551)
        at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:2508)
        at android.view.View.dispatchGenericMotionEvent(View.java:14066)
        at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2551)
        at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:2508)
        at android.view.View.dispatchGenericMotionEvent(View.java:14066)
        at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2551)
        at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:2508)
        at android.view.View.dispatchGenericMotionEvent(View.java:14066)
        at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2551)
        at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:2508)
        at android.view.View.dispatchGenericMotionEvent(View.java:14066)
        at com.android.internal.policy.DecorView.superDispatchGenericMotionEvent(DecorView.java:473)
        at com.android.internal.policy.PhoneWindow.superDispatchGenericMotionEvent(PhoneWindow.java:1859)
        at android.app.Activity.dispatchGenericMotionEvent(Activity.java:4048)
        at androidx.appcompat.view.WindowCallbackWrapper.dispatchGenericMotionEvent(WindowCallbackWrapper.java:79)
        at androidx.appcompat.view.WindowCallbackWrapper.dispatchGenericMotionEvent(WindowCallbackWrapper.java:79)
        at com.android.internal.policy.DecorView.dispatchGenericMotionEvent(DecorView.java:437)
        at android.view.View.dispatchPointerEvent(View.java:14214)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5652)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5455)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4958)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5011)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4977)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5117)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4985)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5174)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4958)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5011)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4977)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4985)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4958)
        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7675)
        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7644)
        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7605)
        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7800)
        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:188)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:336)
        at android.os.Looper.loop(Looper.java:174)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
2020-08-07 21:09:07.719 7068-7122/com.disha.daily_fresh W/CrashlyticsCore: Cannot send reports. Settings are unavailable.
2020-08-07 21:09:07.766 7068-7068/com.disha.daily_fresh I/Process: Sending signal. PID: 7068 SIG: 9

com.disha.daily_fresh.DataBase

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLi`teDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import static com.disha.daily_fresh.Activity.HomeActivity.txt_countcard;


public class DatabaseHelper extends SQLiteOpenHelper {
    public static final String DATABASE_NAME = "mydatabase.db";
    public static final String TABLE_NAME = "items";

    public static final String ICOL_1 = "ID";
    public static final String ICOL_2 = "PID";
    public static final String ICOL_3 = "image";
    public static final String ICOL_4 = "title";
    public static final String ICOL_5 = "weight";
    public static final String ICOL_6 = "cost";
    public static final String ICOL_7 = "qty";
    public static final String ICOL_8 = "discount";


    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, PID TEXT , image TEXT ,title TEXT , weight TEXT , cost TEXT, qty TEXT , discount int )");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        onCreate(db);
    }

    public boolean insertData(MyCart rModel) {
        if (getID(rModel.getPID(), rModel.getCost()) == -1) {
            SQLiteDatabase db = this.getWritableDatabase();
            ContentValues contentValues = new ContentValues();
            contentValues.put(ICOL_2, rModel.getPID());
            contentValues.put(ICOL_3, rModel.getImage());
            contentValues.put(ICOL_4, rModel.getTitle());
            contentValues.put(ICOL_5, rModel.getWeight());
            contentValues.put(ICOL_6, rModel.getCost());
            contentValues.put(ICOL_7, rModel.getQty());
            contentValues.put(ICOL_8, rModel.getDiscount());
            long result = db.insert(TABLE_NAME, null, contentValues);

            if (result == -1) {
                return false;
            } else {
                Cursor resw = getAllData();
                txt_countcard.setText("" + resw.getCount());
                return true;
            }
        } else {

            return updateData(rModel.getPID(), rModel.getCost(), rModel.getQty());
        }
    }

    private int getID(String pid, String cost) {
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor c = db.query(TABLE_NAME, new String[]{"PID"}, "PID =? AND cost =? ", new String[]{pid, cost}, pid, null, null, null);
        if (c.moveToFirst()) //if the row exist then return the id
            return c.getInt(c.getColumnIndex("PID"));
        return -1;
    }

    public int getCard(String pid, String cost) {
        SQLiteDatabase db = this.getWritableDatabase();

        Cursor c = db.query(TABLE_NAME, new String[]{"qty"}, "PID =? AND cost =? ", new String[]{pid, cost}, null, null, null, null);
        if (c.moveToFirst()) { //if the row exist then return the id
            return c.getInt(c.getColumnIndex("qty"));
        } else {
            return -1;

        }
    }

    public Cursor getAllData() {
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor res = db.rawQuery("select * from " + TABLE_NAME, null);
        return res;
    }
    public boolean updateData(String id, String cost, String status) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(ICOL_7, status);
        db.update(TABLE_NAME, contentValues, "PID = ? AND cost =?", new String[]{id, cost});
        Cursor res = getAllData();
        txt_countcard.setText("" + res.getCount());
        return true;
    }

Anshu IT, [07.08.20 21:41]
public void DeleteCard(){
        SQLiteDatabase db = this.getWritableDatabase();
        db.execSQL("delete from "+ TABLE_NAME);
        txt_countcard.setText("0");
    }

    public Integer deleteRData(String id, String cost) {
        SQLiteDatabase db = this.getWritableDatabase();
        Integer a = db.delete(TABLE_NAME, "PID = ? AND cost =?", new String[]{id, cost});
        Cursor res = getAllData();
        txt_countcard.setText("" + res.getCount());
        return a;
    }
}

Adapter java

package com.disha.daily_fresh.DataBase;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import static com.disha.daily_fresh.Activity.HomeActivity.txt_countcard;

public class DatabaseHelper extends SQLiteOpenHelper {
    public static final String DATABASE_NAME = "mydatabase.db";
    public static final String TABLE_NAME = "items";

    public static final String ICOL_1 = "ID";
    public static final String ICOL_2 = "PID";
    public static final String ICOL_3 = "image";
    public static final String ICOL_4 = "title";
    public static final String ICOL_5 = "weight";
    public static final String ICOL_6 = "cost";
    public static final String ICOL_7 = "qty";
    public static final String ICOL_8 = "discount";


    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, PID TEXT , image TEXT ,title TEXT , weight TEXT , cost TEXT, qty TEXT , discount int )");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        onCreate(db);
    }

    public boolean insertData(MyCart rModel) {
        if (getID(rModel.getPID(), rModel.getCost()) == -1) {
            SQLiteDatabase db = this.getWritableDatabase();
            ContentValues contentValues = new ContentValues();
            contentValues.put(ICOL_2, rModel.getPID());
            contentValues.put(ICOL_3, rModel.getImage());
            contentValues.put(ICOL_4, rModel.getTitle());
            contentValues.put(ICOL_5, rModel.getWeight());
            contentValues.put(ICOL_6, rModel.getCost());
            contentValues.put(ICOL_7, rModel.getQty());
            contentValues.put(ICOL_8, rModel.getDiscount());
            long result = db.insert(TABLE_NAME, null, contentValues);

            if (result == -1) {
                return false;
            } else {
                Cursor resw = getAllData();
                txt_countcard.setText("" + resw.getCount());
                return true;
            }
        } else {

            return updateData(rModel.getPID(), rModel.getCost(), rModel.getQty());
        }
    }

    private int getID(String pid, String cost) {
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor c = db.query(TABLE_NAME, new String[]{"PID"}, "PID =? AND cost =? ", new String[]{pid, cost}, pid, null, null, null);
        if (c.moveToFirst()) //if the row exist then return the id
            return c.getInt(c.getColumnIndex("PID"));
        return -1;
    }

    public int getCard(String pid, String cost) {
        SQLiteDatabase db = this.getWritableDatabase();

        Cursor c = db.query(TABLE_NAME, new String[]{"qty"}, "PID =? AND cost =? ", new String[]{pid, cost}, null, null, null, null);
        if (c.moveToFirst()) { //if the row exist then return the id
            return c.getInt(c.getColumnIndex("qty"));
        } else {
            return -1;

        }
    }

    public Cursor getAllData() {
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor res = db.rawQuery("select * from " + TABLE_NAME, null);
        return res;
    }


    public boolean updateData(String id, String cost, String status) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(ICOL_7, status);
        db.update(TABLE_NAME, contentValues, "PID = ? AND cost =?", new String[]{id, cost});
        Cursor res = getAllData();
        txt_countcard.setText("" + res.getCount());
        return true;
    }

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.disha.daily_fresh.Activity.ItemDetailsActivity;
import com.disha.daily_fresh.DataBase.DatabaseHelper;
import com.disha.daily_fresh.DataBase.MyCart;
import com.disha.daily_fresh.Model.Price;
import com.disha.daily_fresh.Model.ProductItem;
import com.disha.daily_fresh.R;
import com.disha.daily_fresh.Utils.SessionManager;
import com.disha.daily_fresh.retrofit.APIClient;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.disha.daily_fresh.Fragment.ItemListFragment.itemListFragment;
import static com.disha.daily_fresh.Utils.SessionManager.CURRUNCY;

public class ItemAdp extends RecyclerView.Adapter<ItemAdp.ViewHolder> {


    private List<ProductItem> mData;
    private LayoutInflater mInflater;
    private ItemClickListener mClickListener;
    Context mContext;
    private int screenWidth;
    SessionManager sessionManager;
    public ItemAdp(Context context, List<ProductItem> data) {
        this.mInflater = LayoutInflater.from(context);
        this.mData = data;
        this.mContext = context;
        WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        screenWidth = size.x;
        sessionManager=new SessionManager(mContext);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_custome, parent, false);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        ProductItem datum = mData.get(position);
        Glide.with(mContext).load(APIClient.Base_URL + "/" + datum.getProductImage()).thumbnail(Glide.with(mContext).load(R.drawable.ezgifresize)).into(holder.imgIcon);

        holder.txtTitle.setText("" + datum.getProductName());
        if (!datum.getSellerName().equals("")) {
            holder.sellerName.setText("" + datum.getSellerName());
        } else {
            holder.sellerName.setVisibility(View.GONE);
        }
        if (!datum.getShortDesc().equals("")) {
            holder.shortDesc.setText("" + datum.getShortDesc());
            if (holder.shortDesc.getText().toString().length() < 90) {

            } else {
                makeTextViewResizable(holder.shortDesc, 3, "See More", true);
            }


        } else {
            holder.shortDesc.setVisibility(View.GONE);
        }
        holder.imgIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mContext.startActivity(new Intent(mContext, ItemDetailsActivity.class).putExtra("MyClass", datum).putParcelableArrayListExtra("MyList", datum.getPrice()));
            }
        });
        if (datum.getmDiscount() > 0) {
            holder.lvlOffer.setVisibility(View.VISIBLE);
            holder.txtOffer.setText(datum.getmDiscount() + "% Off");
        } else {
            holder.lvlOffer.setVisibility(View.GONE);

        }
        setJoinPlayrList(holder.lvlSubitem, datum);
    }

Anshu IT, [07.08.20 21:42]
@Override
    public int getItemCount() {
        return mData.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        @BindView(R.id.txtTitle)
        TextView txtTitle;
        @BindView(R.id.txt_offer)
        TextView txtOffer;
        @BindView(R.id.seller_name)
        TextView sellerName;
        @BindView(R.id.short_desc)
        TextView shortDesc;
        @BindView(R.id.lvl_subitem)
        LinearLayout lvlSubitem;
        @BindView(R.id.lvl_offer)
        LinearLayout lvlOffer;


        @BindView(R.id.img_icon)
        ImageView imgIcon;


        ViewHolder(View itemView) {

            super(itemView);
            ButterKnife.bind(this, itemView);
            itemView.setOnClickListener(this);

        }

        @Override
        public void onClick(View view) {
            if (mClickListener != null) mClickListener.onItemClick(view, getAdapterPosition());
        }
    }

//    String getItem(int id) {
//        return mData.get(id);
//    }

    void setClickListener(ItemClickListener itemClickListener) {
        this.mClickListener = itemClickListener;
    }

    public interface ItemClickListener {
        void onItemClick(View view, int position);
    }
    private void setJoinPlayrList(LinearLayout lnrView, ProductItem datum) {
        List<Price> priceList = datum.getPrice();
        lnrView.removeAllViews();
        final int[] count = {0};
        DatabaseHelper helper = new DatabaseHelper(lnrView.getContext());
        if (priceList != null && priceList.size() > 0) {
            for (int i = 0; i < priceList.size(); i++) {
                LayoutInflater inflater = LayoutInflater.from(mContext);

                View view = inflater.inflate(R.layout.custome_prize, null);

                TextView txt_price = view.findViewById(R.id.txt_price);
                TextView txt_gram = view.findViewById(R.id.txt_gram);
                TextView txt_offer = view.findViewById(R.id.txt_offer);
                TextView txtcount = view.findViewById(R.id.txtcount);
                LinearLayout img_mins = view.findViewById(R.id.img_mins);
                LinearLayout img_plus = view.findViewById(R.id.img_plus);
                MyCart myCart = new MyCart();
                myCart.setPID(datum.getId());
                myCart.setImage(datum.getProductImage());
                myCart.setTitle(datum.getProductName());
                myCart.setWeight(datum.getPrice().get(i).getProductType());
                myCart.setCost(datum.getPrice().get(i).getProductPrice());
                myCart.setDiscount(datum.getmDiscount());
                int qrt = helper.getCard(myCart.getPID(), myCart.getCost());
                if (qrt != -1) {
                    count[0] = qrt;
                    txtcount.setText("" + count[0]);
                    txtcount.setVisibility(View.VISIBLE);
                } else {
                    txtcount.setVisibility(View.VISIBLE);
                    img_mins.setVisibility(View.VISIBLE);
                }
                img_mins.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        count[0] = Integer.parseInt(txtcount.getText().toString());

Anshu IT, [07.08.20 21:42]
count[0] = count[0] - 1;
                        if (count[0] <= 0) {
                            img_mins.setVisibility(View.VISIBLE);
                            txtcount.setText("0");
                            txtcount.setVisibility(View.VISIBLE);
                            helper.deleteRData(myCart.getPID(), myCart.getCost());
                        } else {
                            txtcount.setVisibility(View.VISIBLE);
                            txtcount.setText("" + count[0]);
                            myCart.setQty(String.valueOf(count[0]));
                            Log.e("INsert", "--> " + helper.insertData(myCart));
                        }
                        itemListFragment.updateItem();
                    }
                });

                img_plus.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        txtcount.setVisibility(View.VISIBLE);
                        img_mins.setVisibility(View.VISIBLE);
                        count[0] = Integer.parseInt(txtcount.getText().toString());

                        count[0] = count[0] + 1;
                        txtcount.setText("" + count[0]);
                        myCart.setQty(String.valueOf(count[0]));
                        Log.e("INsert", "--> " + helper.insertData(myCart));
                        itemListFragment.updateItem();
                    }
                });


                txt_gram.setText("" + priceList.get(i).getProductType());

                if (datum.getmDiscount() > 0) {
                    double  res = (Double.parseDouble(priceList.get(i).getProductPrice()) / 100.0f)* datum.getmDiscount();
                    res = Integer.parseInt(priceList.get(i).getProductPrice()) - res;
                    txt_offer.setText(sessionManager.getStringData(CURRUNCY) + priceList.get(i).getProductPrice());
                    txt_offer.setPaintFlags(txt_offer.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                    txt_price.setText(sessionManager.getStringData(CURRUNCY)  + res);
                } else {
                    txt_offer.setVisibility(View.GONE);
                    txt_price.setText(sessionManager.getStringData(CURRUNCY)  + priceList.get(i).getProductPrice());
                }
                lnrView.addView(view);
            }
}


Solution

  • Error is you are passing value(pid) in groupby, which require column name

    Cursor c = db.query(TABLE_NAME, new String[]{"PID"}, "PID =? AND cost =? ", new String[]{pid, cost}, pid, null, null, null);
    

    If you need to groupby provide column name(PID) not value like this, and your query is not effective as you are passing pid as value and getting pid new String[]{"PID"} , if you need to get all columns replace this by null or if you wish to get selected columns please add more column:

    Cursor c = db.query(TABLE_NAME,null, "PID =? AND cost =? ", new String[]{pid, cost}, null, null, null, null);