This is project for video recorder.The only problem I am having is retrieving stored uri of video from sqllite.The project works fine if I don't call retrieveVid() method but it crashes out when retrieveVid() method is called.Here I am trying to retrieve the uri stored at column 1 and row 2 of sqllite database.Inside checkEvents() method I have commented the other codes which I have tried . Problem might be in checkEvents() or getEvents() method or retrieveVid() method.Since I am running the project on mobile as camera doesn't work on my emulator so i don't have logcat.I am not posting SecondActvity.java as it is not related to database or my problem.
logcat
06-25 21:36:24.501: E/CursorWindow(23206): Failed to read row 2, column 1 from a CursorWindow which has 123 rows, 1 columns.
06-25 21:36:24.504: D/AndroidRuntime(23206): Shutting down VM
06-25 21:36:24.504: W/dalvikvm(23206): threadid=1: thread exiting with uncaught exception (group=0x40e89908)
06-25 21:36:24.514: E/AndroidRuntime(23206): FATAL EXCEPTION: main
06-25 21:36:24.514: E/AndroidRuntime(23206): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=200, result=-1, data=Intent { dat=file:///storage/sdcard0/Pictures/Hello Camera/VID_20140625_213611.mp4 }} to activity {com.example.Assignment/com.example.Assignment.MainActivity}: java.lang.IllegalStateException: Couldn't read row 2, col 1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
06-25 21:36:24.514: E/AndroidRuntime(23206): at android.app.ActivityThread.deliverResults(ActivityThread.java:3302)
06-25 21:36:24.514: E/AndroidRuntime(23206): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3345)
06-25 21:36:24.514: E/AndroidRuntime(23206): at android.app.ActivityThread.access$1100(ActivityThread.java:149)
06-25 21:36:24.514: E/AndroidRuntime(23206): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1348)
06-25 21:36:24.514: E/AndroidRuntime(23206): at android.os.Handler.dispatchMessage(Handler.java:99)
06-25 21:36:24.514: E/AndroidRuntime(23206): at android.os.Looper.loop(Looper.java:153)
06-25 21:36:24.514: E/AndroidRuntime(23206): at android.app.ActivityThread.main(ActivityThread.java:5086)
06-25 21:36:24.514: E/AndroidRuntime(23206): at java.lang.reflect.Method.invokeNative(Native Method)
06-25 21:36:24.514: E/AndroidRuntime(23206): at java.lang.reflect.Method.invoke(Method.java:511)
06-25 21:36:24.514: E/AndroidRuntime(23206): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
06-25 21:36:24.514: E/AndroidRuntime(23206): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
06-25 21:36:24.514: E/AndroidRuntime(23206): at dalvik.system.NativeStart.main(Native Method)
06-25 21:36:24.514: E/AndroidRuntime(23206): Caused by: java.lang.IllegalStateException: Couldn't read row 2, col 1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
06-25 21:36:24.514: E/AndroidRuntime(23206): at android.database.CursorWindow.nativeGetString(Native Method)
06-25 21:36:24.514: E/AndroidRuntime(23206): at android.database.CursorWindow.getString(CursorWindow.java:434)
06-25 21:36:24.514: E/AndroidRuntime(23206): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
06-25 21:36:24.514: E/AndroidRuntime(23206): at com.example.Assignment.MainActivity.checkEvents(MainActivity.java:367)
06-25 21:36:24.514: E/AndroidRuntime(23206): at com.example.Assignment.MainActivity.retrieveVid(MainActivity.java:374)
06-25 21:36:24.514: E/AndroidRuntime(23206): at com.example.Assignment.MainActivity.onActivityResult(MainActivity.java:321)
06-25 21:36:24.514: E/AndroidRuntime(23206): at android.app.Activity.dispatchActivityResult(Activity.java:5204)
06-25 21:36:24.514: E/AndroidRuntime(23206): at android.app.ActivityThread.deliverResults(ActivityThread.java:3298)
06-25 21:36:24.514: E/AndroidRuntime(23206): ... 11 more
Column indexing starts at 0. Your table has only 1 column. You don't specify a projection so all columns are returned in the cursor. Attempting to retrieve the value at column index 1 causes the exception.
To fix it, change getString(1) to getString(0).
First off, you try to read the second row of your cursor without checking if it is there. Also, like #laalto said, the columns on the cursor are zero-based, so with ´getString(1)´ you won't get anything, because the table has only one column.
I'd recommend you to get the String like this, this will be save, even if you add further rows to your Table:
if(cursor.moveToPosition(2)){
a = cursor.getString(cursor.getColumnIndex(sql.COLUMN_VID));
// add a constant (COLUMN_VID) to your sql class which defines the row name and also use this constant in your table creation
}
Related
I am using SQlite database to store data.. but when I try to sum the columns using query I am getting error Column doesn't exists like below:
select _id, column1, sum(column2),sum(column3) from table
At the same time when I write without sum I am able to see the result in application as below.
select _id, column1, column2,column3 from table
Column2 and Column3 are Real data type columns.
I have no clue about this behaviour, why it is behaving this way.
Code to retrieve the columns from cursor.
summaryviewholder.Total.setText(String.valueOf(getsummary.getInt(getsummary.getColumnIndexOrThrow(st.column2))));
Logcat:
E/AndroidRuntime(8187): FATAL EXCEPTION: main
06-25 15:53:24.011: E/AndroidRuntime(8187): Process: com.example.portfoliomanager, PID: 8187
06-25 15:53:24.011: E/AndroidRuntime(8187): java.lang.IllegalArgumentException: column 'Buy_Qua' does not exist
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:303)
06-25 15:53:24.011: E/AndroidRuntime(8187): at com.example.StockDirector.stockmanager$popsummarystock.bindView(stockmanager.java:518)
06-25 15:53:24.011: E/AndroidRuntime(8187): at com.example.StockDirector.stockmanager$popsummarystock.newView(stockmanager.java:539)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.widget.CursorAdapter.getView(CursorAdapter.java:250)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.widget.AbsListView.obtainView(AbsListView.java:2720)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.widget.ListView.measureHeightOfChildren(ListView.java:1274)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.widget.ListView.onMeasure(ListView.java:1186)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.View.measure(View.java:17387)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.widget.RelativeLayout.measureChild(RelativeLayout.java:689)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:473)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.View.measure(View.java:17387)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.View.measure(View.java:17387)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.View.measure(View.java:17387)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
06-25 15:53:24.011: E/AndroidRuntime(8187): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:391)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.View.measure(View.java:17387)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
06-25 15:53:24.011: E/AndroidRuntime(8187): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2533)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.View.measure(View.java:17387)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2214)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1351)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1550)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1235)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6476)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.Choreographer.doCallbacks(Choreographer.java:603)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.Choreographer.doFrame(Choreographer.java:573)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.os.Handler.handleCallback(Handler.java:733)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.os.Handler.dispatchMessage(Handler.java:95)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.os.Looper.loop(Looper.java:157)
06-25 15:53:24.011: E/AndroidRuntime(8187): at android.app.ActivityThread.main(ActivityThread.java:5356)
06-25 15:53:24.011: E/AndroidRuntime(8187): at java.lang.reflect.Method.invokeNative(Native Method)
06-25 15:53:24.011: E/AndroidRuntime(8187): at java.lang.reflect.Method.invoke(Method.java:515)
06-25 15:53:24.011: E/AndroidRuntime(8187): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
06-25 15:53:24.011: E/AndroidRuntime(8187): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
06-25 15:53:24.011: E/AndroidRuntime(8187): at dalvik.system.NativeStart.main(Native Method)
06-25 15:53:25.486: I/Process(8187): Sending signal. PID: 8187 SIG: 9
You have to name your rows you summarize.
Other notes:
If you use sum (or aggregation function in general), you can't select other rows that are not aggregated, or else you won't get a proper result.
Also, use Float for getting the value from the database, as you use the Real datatype (floating point number) in sqlite.
So instead of this:
select _id, column1, sum(column2),sum(column3) from table
You have to do something like this:
select column1, sum(column2) AS sum1, sum(column3) AS sum2 from table group by column1;
And to the values:
summaryviewholder.Total.setText(String.valueOf(getsummary.getFloat(getsummary.getColumnIndexOrThrow("sum1"))));
When you write SELECT sum(Column2), then the name of the output column is sum(Column2).
You should either read the column values by their index (which is dangerous when the query ever changes), or give the output column another name:
SELECT sum(Column2) AS Column2Sum ...
I am working on Card Scanner application, Using native camera and barcode scanning apis in my app(everything is fine with camera and barcode sanning), also using Spring Android library with Java POJO Objects for in/out to Rest apis.
ISSUE
Android is closing my application without any notification, QA reported a bug that he was testing and suddenly app closed(behavior is similar to home button press).
I don't have any idea about this issue. I reproduced this issue at my end and got below mentioned logs in logcat.
Here is my logs:
01-29 14:35:00.805: E/AndroidRuntime(25696): FATAL EXCEPTION: main
01-29 14:35:00.805: E/AndroidRuntime(25696): Process: com.ihi.bcr, PID: 25696
01-29 14:35:00.805: E/AndroidRuntime(25696): java.lang.RuntimeException: Unable to start service com.ihi.bcr.services.ContactSyncService#44e4fbf8 with Intent { flg=0x10000000 cmp=com.ihi.bcr/.services.ContactSyncService }: java.lang.NullPointerException
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2719)
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.app.ActivityThread.access$2100(ActivityThread.java:135)
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.os.Handler.dispatchMessage(Handler.java:102)
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.os.Looper.loop(Looper.java:136)
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.app.ActivityThread.main(ActivityThread.java:5017)
01-29 14:35:00.805: E/AndroidRuntime(25696): at java.lang.reflect.Method.invokeNative(Native Method)
01-29 14:35:00.805: E/AndroidRuntime(25696): at java.lang.reflect.Method.invoke(Method.java:515)
01-29 14:35:00.805: E/AndroidRuntime(25696): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
01-29 14:35:00.805: E/AndroidRuntime(25696): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
01-29 14:35:00.805: E/AndroidRuntime(25696): at dalvik.system.NativeStart.main(Native Method)
01-29 14:35:00.805: E/AndroidRuntime(25696): Caused by: java.lang.NullPointerException
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.app.IntentService.onStart(IntentService.java:116)
01-29 14:35:00.805: E/AndroidRuntime(25696): at roboguice.service.RoboIntentService.onStart(RoboIntentService.java:66)
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.app.IntentService.onStartCommand(IntentService.java:130)
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2702)
01-29 14:35:00.805: E/AndroidRuntime(25696): ... 10 more
01-29 14:35:00.815: W/ActivityManager(780): Force finishing activity com.ihi.bcr/.activity.HomeScreen
01-29 14:35:00.975: E/Database(19015): 0
01-29 14:35:01.185: E/Database(19015): 0
01-29 14:35:01.215: D/audio_hw_primary(184): select_devices: out_snd_device(2: speaker) in_snd_device(0: )
01-29 14:35:01.345: W/ActivityManager(780): Activity pause timeout for ActivityRecord{4382e1c0 u0 com.ihi.bcr/.activity.HomeScreen t171 f}
01-29 14:35:01.405: E/Database(19015): 0
01-29 14:35:01.645: D/dalvikvm(19015): GC_FOR_ALLOC freed 527K, 4% free 17113K/17728K, paused 24ms, total 25ms
NOTE:
ContactSyncService is intent service.
I am starting contactSyncService by startService() method.
I didn't override onStart and onStartCommand() functions of IntentService(As it is mention in Android Docs)
You have missed to call super.onCreate() in your ContactSyncService.onCreate().
I have instantiated a fragment type that extends CameraFragment (and implements TabListener), and I am trying to call the autoFocus() from the the parent Activity. Calling autoFocus() from the fragment that extends CameraFragment works fine, but calling it from the parent Activity results in an NPE. I am listening for a onKeyDown() event in the main Activity, which works as expected as per the logcat. Here is my NPE trace:
09-10 10:00:16.410: D/app(5283): onKeyDown: 80
09-10 10:00:16.415: D/AndroidRuntime(5283): Shutting down VM
09-10 10:00:16.415: W/dalvikvm(5283): threadid=1: thread exiting with uncaught exception (group=0x40f7b2a0)
09-10 10:00:16.425: E/AndroidRuntime(5283): FATAL EXCEPTION: main
09-10 10:00:16.425: E/AndroidRuntime(5283): java.lang.NullPointerException
09-10 10:00:16.425: E/AndroidRuntime(5283): at com.commonsware.cwac.camera.CameraFragment.autoFocus(CameraFragment.java:96)
09-10 10:00:16.425: E/AndroidRuntime(5283): at com.me.app.appCameraFragment.callAutoFocus(cameraFragment.java:232)
09-10 10:00:16.425: E/AndroidRuntime(5283): at com.me.app.MainTabActivity.onKeyDown(MainTabActivity.java:264)
09-10 10:00:16.425: E/AndroidRuntime(5283): at android.view.KeyEvent.dispatch(KeyEvent.java:2705)
09-10 10:00:16.425: E/AndroidRuntime(5283): at android.app.Activity.dispatchKeyEvent(Activity.java:2423)
09-10 10:00:16.425: E/AndroidRuntime(5283): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2019)
09-10 10:00:16.425: E/AndroidRuntime(5283): at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3851)
09-10 10:00:16.425: E/AndroidRuntime(5283): at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:3799)
09-10 10:00:16.425: E/AndroidRuntime(5283): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2934)
09-10 10:00:16.425: E/AndroidRuntime(5283): at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 10:00:16.425: E/AndroidRuntime(5283): at android.os.Looper.loop(Looper.java:137)
09-10 10:00:16.425: E/AndroidRuntime(5283): at android.app.ActivityThread.main(ActivityThread.java:4921)
09-10 10:00:16.425: E/AndroidRuntime(5283): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 10:00:16.425: E/AndroidRuntime(5283): at java.lang.reflect.Method.invoke(Method.java:511)
09-10 10:00:16.425: E/AndroidRuntime(5283): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1036)
09-10 10:00:16.425: E/AndroidRuntime(5283): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:803)
09-10 10:00:16.425: E/AndroidRuntime(5283): at dalvik.system.NativeStart.main(Native Method)
I'm not sure what version of the code you are working on, but line 96 is a closing brace in the current CameraFragment.
The only way autoFocus() can crash with a NullPointerException is if cameraView is null, and the only way cameraView should be null is if onCreateView() has not yet been called. You need the fragment to be visible and fully created before you request auto-focus.
I am trying to integrate the Youtube API into my project. To do so,
I have copied the the necessary jar files from the sdk folder to my project
Added it to my project build path.
I have also obtained a key from google, and added it to the Developer.java file, and it is used at the time of calling the intialize() function.
The program shows no error at build time. However, when it shows the follwing log when I try to initialize. Please help:
06-25 18:26:15.813: E/AndroidRuntime(6197): FATAL EXCEPTION: main
06-25 18:26:15.813: E/AndroidRuntime(6197): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.deltapath.frSIP/hk.d100.VideoPlayer}: java.lang.IllegalArgumentException: callingAppVersion cannot be null or empty
06-25 18:26:15.813: E/AndroidRuntime(6197): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-25 18:26:15.813: E/AndroidRuntime(6197): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-25 18:26:15.813: E/AndroidRuntime(6197): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-25 18:26:15.813: E/AndroidRuntime(6197): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-25 18:26:15.813: E/AndroidRuntime(6197): at android.os.Handler.dispatchMessage(Handler.java:99)
06-25 18:26:15.813: E/AndroidRuntime(6197): at android.os.Looper.loop(Looper.java:137)
06-25 18:26:15.813: E/AndroidRuntime(6197): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-25 18:26:15.813: E/AndroidRuntime(6197): at java.lang.reflect.Method.invokeNative(Native Method)
06-25 18:26:15.813: E/AndroidRuntime(6197): at java.lang.reflect.Method.invoke(Method.java:511)
06-25 18:26:15.813: E/AndroidRuntime(6197): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-25 18:26:15.813: E/AndroidRuntime(6197): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-25 18:26:15.813: E/AndroidRuntime(6197): at dalvik.system.NativeStart.main(Native Method)
06-25 18:26:15.813: E/AndroidRuntime(6197): Caused by: java.lang.IllegalArgumentException: callingAppVersion cannot be null or empty
06-25 18:26:15.813: E/AndroidRuntime(6197): at com.google.android.youtube.player.internal.ac.a(Unknown Source)
06-25 18:26:15.813: E/AndroidRuntime(6197): at com.google.android.youtube.player.internal.o.<init>(Unknown Source)
06-25 18:26:15.813: E/AndroidRuntime(6197): at com.google.android.youtube.player.internal.ad.a(Unknown Source)
06-25 18:26:15.813: E/AndroidRuntime(6197): at com.google.android.youtube.player.YouTubePlayerView.a(Unknown Source)
06-25 18:26:15.813: E/AndroidRuntime(6197): at com.google.android.youtube.player.YouTubeBaseActivity$a.a(Unknown Source)
06-25 18:26:15.813: E/AndroidRuntime(6197): at com.google.android.youtube.player.YouTubePlayerView.initialize(Unknown Source)
06-25 18:26:15.813: E/AndroidRuntime(6197): at hk.d100.VideoPlayer.onCreate(VideoPlayer.java:42)
06-25 18:26:15.813: E/AndroidRuntime(6197): at android.app.Activity.performCreate(Activity.java:5104)
06-25 18:26:15.813: E/AndroidRuntime(6197): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-25 18:26:15.813: E/AndroidRuntime(6197): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-25 18:26:15.813: E/AndroidRuntime(6197): ... 11 more
If possible, please include your use of the YouTube API (rather than only the stack trace) so others can help you out.
My main Activity (say A) raises intent to fetch a ContactID from ContactsContract through
startActivityForResult(new Intent(Intent.ACTION_PICK, contactsContract.Contacts.CONTENT_URI),PICK_CONTACT);
While returning (onActivityResult(int reqCode, int resultCode, Intent data)), I am using details from 'data' to query the contacts through
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
......
my code works fine with Android 2.x. However this code gets crashed in ICS (Android 4.x), while resuming the main Activity(A).
I am not sure, whether it is due to the deprecated 'managedQuery'.
Can somebody offer some solution, I am stuck and unable to even find which line causes the error as the Log cat is not showing even the error line number. it simply says
Caused by: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
Thanks in advance
Joshy
I have tried the above code just after completing the requirement of the cursor. Still the problem persists. My Log cat says as follows
08-13 00:26:31.427: W/dalvikvm(3176): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
08-13 00:26:31.447: E/AndroidRuntime(3176): FATAL EXCEPTION: main
08-13 00:26:31.447: E/AndroidRuntime(3176): java.lang.RuntimeException: Unable to resume activity {com.desquare.sp/com.desquare.sp.SmartPadActivity}: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2444)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2472)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1173)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.os.Handler.dispatchMessage(Handler.java:99)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.os.Looper.loop(Looper.java:137)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.ActivityThread.main(ActivityThread.java:4424)
08-13 00:26:31.447: E/AndroidRuntime(3176): at java.lang.reflect.Method.invokeNative(Native Method)
08-13 00:26:31.447: E/AndroidRuntime(3176): at java.lang.reflect.Method.invoke(Method.java:511)
08-13 00:26:31.447: E/AndroidRuntime(3176): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-13 00:26:31.447: E/AndroidRuntime(3176): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-13 00:26:31.447: E/AndroidRuntime(3176): at dalvik.system.NativeStart.main(Native Method)
08-13 00:26:31.447: E/AndroidRuntime(3176): Caused by: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.database.BulkCursorToCursorAdaptor.throwIfCursorIsClosed(BulkCursorToCursorAdaptor.java:75)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.database.BulkCursorToCursorAdaptor.requery(BulkCursorToCursorAdaptor.java:144)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.database.CursorWrapper.requery(CursorWrapper.java:186)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.Activity.performRestart(Activity.java:4505)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.Activity.performResume(Activity.java:4531)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2434)
08-13 00:26:31.447: E/AndroidRuntime(3176): ... 10 more
It sounds like this is the problem:
*
android.database.staledataexception : Access closed cursor
You seem to be getting the cursors using managedQuery.
I had problems with restoring an application, which for some reason in
Icecream Sandwich did not close the cursors properly. The fix was to
do this for all cursors right after using them:
if (cursor != null && !cursor.isClosed()) {
myActivity.stopManagingCursor( cursor );
cursor.close();
}
The API startManagingCursor/stopManagingCursor is deprecated and is the root cause of the issue.
For example, please comment this out and verify.