Not Serializable SQLiteCursor when I go home - java

My app is a RSS adapter who works with SQlite, viewpagers and RecyclerViews. Everything works fine but once I leave my app pressing home button, my app crashes and shows the following logcat:
FATAL EXCEPTION: main
Process: com.herprogramacin.hermosaprogramacion, PID: 14900
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.herprogramacin.hermosaprogramacion.UI.Adapters.RVAdapter)
at android.os.Parcel.writeSerializable(Parcel.java:1468)
at android.os.Parcel.writeValue(Parcel.java:1416)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:686)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330)
at android.os.Bundle.writeToParcel(Bundle.java:1079)
at android.os.Parcel.writeBundle(Parcel.java:711)
at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:137)
at android.os.Parcel.writeTypedArray(Parcel.java:1254)
at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:384)
at android.os.Parcel.writeParcelable(Parcel.java:1437)
at android.os.Parcel.writeValue(Parcel.java:1343)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:686)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330)
at android.os.Bundle.writeToParcel(Bundle.java:1079)
at android.os.Parcel.writeBundle(Parcel.java:711)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3701)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4622)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.io.NotSerializableException: android.database.sqlite.SQLiteCursor
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1344)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:959)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:360)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1054)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
at android.os.Parcel.writeSerializable(Parcel.java:1463)
at android.os.Parcel.writeValue(Parcel.java:1416) 
at android.os.Parcel.writeArrayMapInternal(Parcel.java:686) 
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330) 
at android.os.Bundle.writeToParcel(Bundle.java:1079) 
at android.os.Parcel.writeBundle(Parcel.java:711) 
at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:137) 
at android.os.Parcel.writeTypedArray(Parcel.java:1254) 
at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:384) 
at android.os.Parcel.writeParcelable(Parcel.java:1437) 
at android.os.Parcel.writeValue(Parcel.java:1343) 
at android.os.Parcel.writeArrayMapInternal(Parcel.java:686) 
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330) 
at android.os.Bundle.writeToParcel(Bundle.java:1079) 
at android.os.Parcel.writeBundle(Parcel.java:711) 
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3701) 
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4622) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:158) 
at android.app.ActivityThread.main(ActivityThread.java:7224) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Where we can read "Caused by: java.io.NotSerializableException:android.database.sqlite.SQLiteCursor"
Why Is it happening this?
EDIT 1:
How my app works.
Main activity gets the XML code for RSS and once it finishes, MainActivity get the cursor and generates the Recycler View Adapter.
Main activity creates the viewpager and sends to him the RecyclerView Adapter.
ViewPager creates a new fragment and passes the adapter to the new Fragment
The new fragment generates the view and sets the adapter with the data that ViewPager sent to him.
I realised that is crazy to generate the adapter in MainActivity and pass it to the fragment through 3 clases. Could be this the problem?

It sounds like you are holding a reference to a SQLiteCursor in an activity or other view logic. When Android is attempting to pause your activity it tries to serialize the data the activity currently has (and dependent objects) so that they can be deserialized when the activity resumes. Look around for how you are using SQLiteCursor, you should not be passing them around to your activity or any model objects used by your activity.

Related

My Activity is getting null object exception when the app resumes after bing in the background

I have an android app that has a second module included in the app when the main activity starts an activity in the module everything is good. The problem is if you go to another app and then resume this app the activity crashes with a null object pointer. My app uses Esri ArcGIS runtime SDK. I have a MapView open in the activity when the crash occurs. I don't have any problem with an open map in the MainActivity and the app goes to the background then back to the current app.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.thevillages.myfirstapp, PID: 23267
java.lang.RuntimeException: Unable to resume activity {com.thevillages.myfirstapp/com.thevillages.maplib.MapNavActivity}: com.esri.arcgisruntime.ArcGISRuntimeException: Null pointer.: object cannot be null.
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4205)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4237)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
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)
Caused by: com.esri.arcgisruntime.ArcGISRuntimeException: Null pointer.: object cannot be null.
at com.esri.arcgisruntime.internal.jni.CoreGeoView.nativeResume(Native Method)
at com.esri.arcgisruntime.internal.jni.CoreGeoView.b(SourceFile:5)
at com.esri.arcgisruntime.a.i.f.g.d(SourceFile:3)
at com.esri.arcgisruntime.mapping.view.GeoView$RenderingThread.resume(SourceFile:4)
at com.esri.arcgisruntime.mapping.view.MapView.resume(SourceFile:1)
at com.thevillages.maplib.MapNavActivity.onResume(MapNavActivity.java:816)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1446)
at android.app.Activity.performResume(Activity.java:7939)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4195)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4237) 
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) 
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:214) 
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)
I systematically went through my onCreate() method and added each piece of the code to find where the problem was. I found some code that was suspicious and I could not recall why I added the code. With the code removed the app works fine.

How to add Internet Connection Problem Dialog in android app on Async Task

I want to add Internet Connection Problem Dialog in my Async Task subclass. I tried many methods but the same error happened when my internet not connected.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.yasht.cricketapp, PID: 12793
java.lang.ClassCastException: java.lang.String cannot be cast to java.io.InputStream
at com.example.yasht.cricketapp.m_Rss.Downloader.onPostExecute(Downloader.java:66)
at android.os.AsyncTask.finish(AsyncTask.java:667)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:684)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Error Pointing On 66 line:
Please comment If you want any other information.
You are casting data into inputStream, if you want to create this object you should do something like : ByteArrayInputStream( data.getBytes() )
probably you should post your onExecute too to see what are you trying to do

Android testfairy java.lang.VerifyError?

After I upload my apk to testfairy and install it I get a java.lang.VerifyError crash
The class extends android.support.v4.app.Fragment
This is the function that is crashing. It crashes on the function execution, not the click but when I remove the onClick. Inner stuff all works.
fitroom_lly is LinearLayout
mixpanel defined :
MixpanelAPI mixpanel = MixpanelAPI.getInstance(getActivity(), getResources().getString(R.string.Mix_Panel_Token));
Function:
private void AddOnFittingRoomClickListener() {
fitroom_lly.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mixpanel.track("Fitting room");
}
});
}
Error:
java.lang.VerifyError: co/slider/fashion/Slider/SliderFragment$6
at co.slider.fashion.Slider.SliderFragment.AddOnFittingRoomClickListener(SliderFragment.java:334)
at co.slider.fashion.Slider.SliderFragment.onCreateView(SliderFragment.java:135)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
I work for TestFairy. I need a bit information, is your app multidex'd or a single dex? That's the only VerifyError we ever encountered, and we have an answer for that. Though I would need you to email support at testfairy.com, and one of the technical developer will explain to you the workaround. We're making this solution available to everybody, but in the meanwhile, only support is explaining this.

java.lang.IllegalStateException: Fragment does not have a view

I have an activity which displays a DialogFragment, inside that dialog fragment I have a linearlayout which contains one button, and a fragmentLAyout where I want to display the info.
I´d have to display one list of elements, and if any of them are pressed I´ll have to display the details for them. I thought the best way to do that is with fragments, when trying to call
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.framePlaceHolder, listAccountFragment).commit();
after creating my listAccountFragment, I´m getting this error
10-01 10:53:34.004 12836-12836/com.bbva.compassBuzz.qa.debug E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.bbva.compassBuzz.qa.debug, PID: 12836
java.lang.IllegalStateException: Fragment does not have a view
at android.support.v4.app.Fragment$1.findViewById(Fragment.java:1746)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:943)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)
at android.support.v4.app.Fragment.performResume(Fragment.java:1836)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:993)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:456)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5253)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1384)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1179)

IllegalStateException: Fragment Already Added when resuming app

Overview:
I have a fragment-based app with a single activity. On launch, I add my main fragment and all works well. When I tap on something, I call replace() to swap out to the new fragment and add the transaction to the back stack.
Problem:
When the app dies in the background (or most easily repro'd with 'Don't Keep Activities'), and I relaunch the app from the home screen, I get the exception below.
Scenario:
1. Open app
2. Navigate to a secondary fragment (this problem doesn't occur if you never leave the main fragment)
3. Background the app
4. Let the app die naturally (~24hr), or enable 'Don't Keep Activites' in the Developer Options
5. Open app from home screen
Expected:
App opens to main fragment (regardless of what fragment was displayed when backgrounded)
Actual:
Crash below
Other Requirements:
- Background app and immediately tap from home screen must return to previous fragment (assuming it wasn't destroyed in the background).
Stack Trace (note absolutely no calls from my app itself, so nowhere for me to debug):
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rcg.socialstitch/com.rcg.socialstitch.ViewStitchActivity}: java.lang.IllegalStateException: Fragment already added: ViewStitchFragment{42800520 #1 id=0x7f040030}
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2227)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2276)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.IllegalStateException: Fragment already added: ViewStitchFragment{42800520 #1 id=0x7f040030}
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1133)
at android.app.BackStackRecord.run(BackStackRecord.java:618)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
at android.app.Activity.performStart(Activity.java:5320)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2190)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2276)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(NativeStart.java)
I believe I have solved this. My .replace() calls all added to the back stack, but my initial .add() did not. When I ensured my initial fragment addition was no the back stack, this no longer seems to happen.

Categories