Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite DatabaseUtils.queryNumEntries does not work on real device but works on the emulator

Tags:

android

sqlite

I am using the following methods count my rows

long numRows = DatabaseUtils.queryNumEntries(ourDatabase, "fuel_table");

And entries in a column with

 long mileagenum = DatabaseUtils.queryNumEntries(ourDatabase, FUEL_DATABASE_TABLE, KEY_MILEAGE);

Both methods work fine on the emulator but give errors on the real device...

Any idea whats going wrong? Thank you.

I get an error log as:-

java.lang.NoSuchMethodError: android.database.DatabaseUtils.queryNumEntries
at com.poojag.fuelcheck.FuelStoredInfo.getAvgMileage(FuelStoredInfo.java:252)
at com.poojag.fuelcheck.Prediction.onFocusChange(Prediction.java:199)
at android.view.View.onFocusChanged(View.java:2742)
at android.widget.TextView.onFocusChanged(TextView.java:6957)
at android.view.View.handleFocusGainInternal(View.java:2565)
at android.view.View.requestFocus(View.java:3720)
at android.view.View.requestFocus(View.java:3671)
at android.view.View.requestFocus(View.java:3649)
at android.view.View.onTouchEvent(View.java:4445)
at android.widget.TextView.onTouchEvent(TextView.java:7130)
at android.widget.EditText.onTouchEvent(EditText.java:143)
at android.view.View.dispatchTouchEvent(View.java:3885)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1750)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1135)
at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1734)
at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2216)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1887)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
like image 282
Pooja Gaonkar Avatar asked Aug 15 '13 13:08

Pooja Gaonkar


1 Answers

queryNumEntries with selection was introduced in API level 11. Your 2.3.6 device is running API level 10.

You can replace it with a regular COUNT(*) selection query, for example:

long mileagenum = DatabaseUtils.longForQuery(ourDatabase,
        "SELECT COUNT(*) FROM " + FUEL_DATABASE_TABLE + " WHERE " + KEY_MILEAGE, null);
like image 116
laalto Avatar answered Oct 04 '22 00:10

laalto