简体   繁体   中英

SharedPreferences error when updating app

When updating my application i get this error, only sometimes.

java.lang.StackOverflowError

at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:354) at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:146) at it.veneto.arpa.controller.Controller.verifyBulletin(Controller.java:377) at it.veneto.arpa.controller.Controller.retrieveBulletin(Controller.java:509) at it.veneto.arpa.controller.Controller.verifyBulletin(Controller.java:394) at it.veneto.arpa.controller.Controller.retrieveBulletin(Controller.java:509) at it.veneto.arpa.controller.Controller.verifyBulletin(Controller.java:394) at it.veneto.arpa.controller.Controller.retrieveBulletin(Controller.java:509) at it.veneto.arpa.controller.Controller.verifyBulletin(Controller.java:394)

on line 377 there is:

SharedPreferences prefs = context.getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE);

If you are connecting to a server (I am assuming because of retrieveBulletin method) again and again, try waiting (Thread.sleep(TIME_OUT);) for a second or two before you try again. Have a maximum number of tries. Say if you tried 10 times already and still didn't receive a response or any valid response, try handling that situation rather than forever trying. If you don't, this will eventually result to an insufficient stack space and you will end up getting the error you are receiving.

Based from your comment, similar situation - bad recursive call without handling the worst scenario.

I believe your verifyBulletin and retrieveBulletin are calling each-other infinite times. Make sure that they are not calling each-other or if they call each-other there is an end condition. If the end condition is fulfilled do not call the other method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM