How to fix error java.util.ConcurrentModificationException? - android

I have some problem with java.util.ConcurrentModificationException. When I deleted one characater or more in my autocompletetext I got force close. Anybody knows what happen with that ? and what is the solution for that problem ?
Thank You.

It looks like you are adding and deleting something from your collection at same point of time. By doing this, you are structurally modifying the collections more than once at single point of time. Hence you are getting java.util.ConcurrentModificationException, which is the result of "Fail-Fast" iterators being used in your collections.
You can have a look at this link which explains fail-safe and fail-fast iterators.
what-is-fail-safe-fail-fast-iterators-in-java-how-they-are-implemented and checkout the answer written by Stephen C.

Related

Doing calculation in android edtitext on lostfocus

I'm writing an app the is does a lot of calculating and I'd like to accomplish some calc when I leave an EditText. Nothing fancy, things like entering 7/16 and having 0.4375 as the result or 1.0259 * 7 and having 7.1813 as the result. The function wouldn't be used all the time but would eliminate a couple of steps when needed.
Thanks Steve
I asked the wrong question, but the comment posted got me thinking, needed to look at substrings.
I've figured out what I need.

Is there a way to trace who invoked onNext() on a Subject, in RxJava(2)?

I am developing an Android app (It doesn't matter though) using RxJava2, and in some singleton there are some PublishProcessors.
And there are a lot of .onNext() calls on these PublishProcessors all over the project.
Now in order to debug, I need to know, on every .onNext() called, which line in my project invoked this .onNext().
Is there a way in RxJava(2) that I can achieve this?
I think you can use Frames tab in Debug menu.
For example, in this case, MainActivity line 18 trigger onNext
Ah, thanks to #PhanVanLinh, I found a solution that worked for me.
(Actually it has pretty much nothing to do with RxJava...)
You just need to print the stacktrace using Thread.currentThread.stackTrace and print it to your own string inside doOnNext(), but remember to do it before .observeOn() so that the thread won't switch, it must stay at the original thread that called .onNext(), otherwise you won't get meaningful information.
Then you will know which line that called .onNext().

Chrisbane PullToRefreshListView IllegalStateException

I had to implement iOS like pull to refresh list in my Android app. I decided to go for this library. It's pull to refresh performance is awesome. But I'm facing one random exception which leads to app crash. It happens sometime that IllegalStateException is thrown pointing to this line in PullToRefreshListView.java in InternalListView class code.
return super.dispatchTouchEvent(ev);
I'm unable to understand this issue. Can any body guide me to solve this issue please.
Please check, you might be calling notifyDataSetChanged() too often in short intervals.
You can go through this link.Chrisbane PullToRefreshListView IllegalStateException
Actually I was missing notifyDataSetChanged() in one of the callbacks. Adding resolved the issue. Thanks everyone who spared time to reply to this question.

Android. ACRA. Is putCustomData thread safe

I can't seem to find the answer to this question I'm having:
Is the method from the ACRA library ...
ACRA.getErrorReporter().putCustomData(Name, Content);
... thread safe?
I'd like to call it from two different threads and I'm not sure if i should or not.
I've searched through the documentation but I wasn't able to find anything related to this unfortunately, or maybe I'm just a bad Googleler :)
If you're not sure, buy some insurance:
ErrorReporter er = ACRA.getErrorReporter();
synchronized( er ) {
er.putCustomData( ..., .... );
}
So I think I've figure it out.
Looking through the code I've noticed that the putCustomData method is in fact a call to a HashMap's method, more precisely put.
Upon further search I've found that the method put is not synchronized.
So the answer is no, calling putCustomData from two different threads can create problems for you.
For a solution to the problem: see 323go's idea below. In my case, I already had a singleton class which I used, so I just placed a synchronized method in that class in which I called the putCustomData method.
Note: If I am wrong, someone please let me know, but this is what I was able to find out.

Can't find the source of a DatabaseObjectNotClosedException error

I'm having a hard time figuring out what my problem is here. I'm receiving this error in my program, but it does not cause a crash or anything like that. I have an update I'd like to release, but I don't want to release it with this error being thrown at certain times. I've read all related posts on this error, but none apply to my situation.
I've made sure that I am closing my DatabaseHelper and SQLiteDatabase objects. I've also made sure that I'm closing all of my cursors. This error is pointing toward my method getActiveScheduleInfo, which returns a Cursor object. I've made sure that whenever I call this method, the returned cursor is closed in a Finally block.
Is this incorrect to do it this way? In my methods that call getActiveScheduleInfo, I have multiple return statements in them, based on certain conditions. So, instead of closing the cursor before each return line, I surround the condition testing with a Try, and close everything down in my Finally.
Everything looks like it should be working, so I'd really appreciate any help!
Thanks a lot!
Paul
I was able to figure this out! I hope that this helps someone else out there having the same problem.
I wasn't doing anything inherently incorrect here, but was rather taking too long to close some of my cursors. To give you a very brief background, I could not use a Managed Query or use startManagingCursor, since this code was in a custom class, not an activity. I am building against Android 2.0 (API level 5) so I am not using the new CursorLoader object.
I was taking the following steps:
Opening the database.
Creating a new Cursor and performing my query.
Iterating through the cursor and performing the needed tasks
Performing some other logic
Closing the Cursor and Database in a Finally block.
I found out that my step 4, performing some other logic, coming before closing my Cursor, was causing it to, for lack of a better term, timeout and cause this error. From now on, I read the necessary data from the Cursor, and not ONE LINE OF CODE FURTHER, I close the Cursor. :) This has completely eliminated these random errors, and I have clean-running code again.
I hope that helps others having the same problem! Take care,
Paul

Categories

Resources