Android Java - Unable to destroy activity: IndexOutOfBoundsException -


i getting following error whenever close application:

fatal exception: main   process: uk.cal.codename.projectnedry, pid: 24450   java.lang.runtimeexception: unable destroy activity {uk.cal.codename.projectnedry/uk.companyscope.companynavigationactivity.companynavigationactivity}: java.lang.indexoutofboundsexception: index: 0, size: 0       @ android.app.activitythread.performdestroyactivity(activitythread.java:4203)       @ android.app.activitythread.handledestroyactivity(activitythread.java:4221)       @ android.app.activitythread.-wrap6(activitythread.java)       @ android.app.activitythread$h.handlemessage(activitythread.java:1538)       @ android.os.handler.dispatchmessage(handler.java:102)       @ android.os.looper.loop(looper.java:154)       @ android.app.activitythread.main(activitythread.java:6119)       @ java.lang.reflect.method.invoke(native method)       @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:886)       @ com.android.internal.os.zygoteinit.main(zygoteinit.java:776)    caused by: java.lang.indexoutofboundsexception: index: 0, size: 0       @ java.util.arraylist.set(arraylist.java:427)       @ android.support.v4.app.fragmentmanagerimpl.makeinactive(fragmentmanager.java:1662)       @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1452)       @ android.support.v4.app.fragmentmanagerimpl.movefragmenttoexpectedstate(fragmentmanager.java:1528)       @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1595)       @ android.support.v4.app.fragmentmanagerimpl.dispatchdestroy(fragmentmanager.java:2951)       @ android.support.v4.app.fragmentcontroller.dispatchdestroy(fragmentcontroller.java:271)       @ android.support.v4.app.fragmentactivity.ondestroy(fragmentactivity.java:390)       @ android.support.v7.app.appcompatactivity.ondestroy(appcompatactivity.java:209)       @ uk.genericmodelviewpresenter.genericmvpactivity.ondestroy(genericmvpactivity.java:96)       @ uk.companyscope.companynavigationactivity.companynavigationactivity.ondestroy(companynavigationactivity.java:523)       @ android.app.activity.performdestroy(activity.java:6881)       @ android.app.instrumentation.callactivityondestroy(instrumentation.java:1153)       @ android.app.activitythread.performdestroyactivity(activitythread.java:4190)       @ android.app.activitythread.handledestroyactivity(activitythread.java:4221)        @ android.app.activitythread.-wrap6(activitythread.java)        @ android.app.activitythread$h.handlemessage(activitythread.java:1538)        @ android.os.handler.dispatchmessage(handler.java:102)        @ android.os.looper.loop(looper.java:154)        @ android.app.activitythread.main(activitythread.java:6119)        @ java.lang.reflect.method.invoke(native method)        @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:886)        @ com.android.internal.os.zygoteinit.main(zygoteinit.java:776)  

the parts touch code have written are:

companynavigationactivity:

@override public void ondestroy() {     super.ondestroy();     getspecificimpofgenericpresenter().closerealm(); } 

and superclass genericmvpactivity:

@override public void ondestroy() {     super.ondestroy();     //unbind butterknife bindings     if(munbinder!=null) {         munbinder.unbind();     } } 

from looking @ stacktrace can see fragment related, within android code. companynavigationactivity @ times contain number of fragments, but error occurs whether created or not.

any ideas cause is?

edit 1

the closerealm method in presenter class, removes listeners , closes presenters instance of realm.

public void closerealm() {     this.mrealmdatabase.getinstance().removeallchangelisteners();     this.mrealmdatabase.close(); } 

edit 2

upon further testing seems if create fragments held within viewpager in companynavigationactivity error does not occur. seems occur when there no fragments present within activity.

edit 3

i have narrowed down particular method, starting foreground service. more specifically, startservice call.

     /**      * if foreground location service not running, start      */     private void startlocationservice() {         if (!foregroundlocationservice.is_service_running) {             intent service = new intent(getspecificimpofgenericview().getapplicationcontext(), foregroundlocationservice.class);             service.setaction(serviceconstants.action.startforeground_action);             foregroundlocationservice.is_service_running = true;             getspecificimpofgenericview().getapplicationcontext().startservice(service);         }     } 

surely foreground request should remain in foreground, separate service, , not affect destruction of activity started them?

you should job before super.ondestroy(); destroy instance specific resources first, before destroying superclass resources instance specific resources may depend upon makes sense.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -