Requirements:
- Android SDK
- JDK 1.8
Steps to run app:
-
Connect an android phone or start an android emulator
-
Make sure USB Debugging is on under Developer Options
-
Open the BigText android project in Android Studio or Command Line/Terminal
-
To run using Android Studio, wait for the project to load up and press the green play button on the top right corner and that's it.
-
To run using the Windows Command Line/Terminal, first install the app by typing this in the project root directory:
For Windows:
gradlew installDebug
For Linux / Mac:
./gradlew installDebug
-
Next, find the app on your device/emulator and open it like you would any other app.
The simplest way to recreate a java.util.ConcurrentModificationException is to execute the following code:
import java.util.*;
public class Bobble {
public static void main(String args[]) {
//Let's say we have a list of Strings
List<String> list = new ArrayList<>();
list.add("Hello");
list.add("World");
list.add("Good");
list.add("Morning");
// Now while travering the string using the for-each loop,
for (String s : list) {
// if we try to remove a value from the list like so,
list.remove(s);
}
// This throws a java.util.ConcurrentModificationException
}
}
Two ways can be enlisted to avoid it from happening:
- Classic for loop
import java.util.*;
public class Bobble {
public static void main(String args[]) {
//Let's say we have a list of Strings
List<String> list = new ArrayList<>();
list.add("Hello");
list.add("World");
list.add("Good");
list.add("Morning");
// This does not throw a java.util.ConcurrentModificationException
for (int i = list.size() - 1; i >= 0; i-- ) {
String s = list.get(i);
list.remove(s);
}
}
}
- Iterator
import java.util.*;
public class Bobble {
public static void main(String args[]) {
//Let's say we have a list of Strings
List<String> list = new ArrayList<>();
list.add("Hello");
list.add("World");
list.add("Good");
list.add("Morning");
// This does not throw a java.util.ConcurrentModificationException
for(Iterator<String> itr = list.iterator(); itr.hasNext();){
/* String s = itr.next();
list.remove(s); */ // wrong again
itr.remove(); // right call
}
}
}