The case is like i want myShop cant view those product that already sold out. I have Quantity in my firebase.
private void setUpRecyclerView(){
Query query = itemRef
.orderBy("quantity", Query.Direction.DESCENDING)
.whereEqualTo("sharerName", user)
//.whereNotEqualTo("Quantity", 15)
//.whereNotEqualTo("Quantity", "15")
//.whereGreaterThan("Quantity", 0)
//.whereGreaterThan("Quantity", "0")
.whereEqualTo("sharerUID", uid);
FirestoreRecyclerOptions<FoodModel> options = new FirestoreRecyclerOptions.Builder<FoodModel>()
.setQuery(query, FoodModel.class)
.build();
iFoodSharedAdapter = new iFoodSharedAdapter(options);
RecyclerView recyclerView = findViewById(R.id.isharedfood_recyclerview);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
recyclerView.setAdapter(iFoodSharedAdapter);
}
But it doesnt work.
There are 4 different ways to do it.
First and second both have the same error such as
.whereNotEqualTo("Quantity", 15)
It will show this error
error: cannot find symbol
.whereNotEqualTo("Quantity", 15)
^
symbol: method whereNotEqualTo(String,int)
location: class Query
Third and fourth ways
.whereGreaterThan("Quantity", 0)
Error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.fyp.fypfoodbank, PID: 20331
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fyp.fypfoodbank/com.fyp.fypfoodbank.Activities.iFoodSharedActivity}: java.lang.IllegalArgumentException: Invalid query. You have an inequality where filter (whereLessThan(), whereGreaterThan(), etc.) on field 'Quantity' and so you must also have 'Quantity' as your first orderBy() field, but your first orderBy() is currently on field 'quantity' instead.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3120)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1840)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:6878)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:876)
Caused by: java.lang.IllegalArgumentException: Invalid query. You have an inequality where filter (whereLessThan(), whereGreaterThan(), etc.) on field 'Quantity' and so you must also have 'Quantity' as your first orderBy() field, but your first orderBy() is currently on field 'quantity' instead.
at com.google.firebase.firestore.Query.validateOrderByFieldMatchesInequality(Query.java:439)
at com.google.firebase.firestore.Query.validateNewFilter(Query.java:471)
at com.google.firebase.firestore.Query.whereHelper(Query.java:354)
at com.google.firebase.firestore.Query.whereGreaterThan(Query.java:172)
at com.fyp.fypfoodbank.Activities.iFoodSharedActivity.setUpRecyclerView(iFoodSharedActivity.java:118)
at com.fyp.fypfoodbank.Activities.iFoodSharedActivity.onCreate(iFoodSharedActivity.java:69)
at android.app.Activity.performCreate(Activity.java:7232)
at android.app.Activity.performCreate(Activity.java:7221)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2965)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3120)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1840)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:6878)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:876)
I/Process: Sending signal. PID: 20331 SIG: 9