I have 2 ArrayList<HashMap<String,String>>
- hashMapFinishedList
- hashMapUnfinishedList
Both hashMap have same attributes with different values,
I want to make a comparison between these 2 Arraylist, and if it has the same value, than it has to be deleted from the 1st hashmap,
I tried this code :
public void compareData() {
// TODO Auto-generated method stub
Log.d("Location", "Arrive at compareData");
String a, b;
Log.d("Status",
"Total Finished List "
+ String.valueOf(hashMapFinishedList.size()));
Log.d("Status",
"Total Unfinished List "
+ String.valueOf(hashMapUnfinishedList.size()));
hashMapFixFinishedList.addAll(hashMapFinishedList);
int count = 0;
int count2 = 0;
int size = hashMapFinishedList.size();
for (int i = 0; i < size; i++) {
count++;
Log.d("Status",
"Inside Looping FinishedList, Looping "
+ String.valueOf(count));
for (int j = 0; j < hashMapUnfinishedList.size(); j++) {
count2++;
Log.d("Status", "Inside Looping UnfinishedList, Looping ke "
+ String.valueOf(count2));
a = hashMapFinishedList.get(i).get("finishedListId");
b = hashMapUnfinishedList.get(j).get("unfinishedListId");
if (a.equals(b)) {
Log.d("Status", a + " is equal " + b);
Log.d("Location",
"Attempt to remove "
+ hashMapFinishedList.get(i).get(
"finishedListTitle"));
if (!(i > hashMapFixFinishedList.size()))
hashMapFixFinishedList.remove(i);
} else
Log.d("Status", a + " is not equal " + b);
}
}
}
but it only compares the first hashmap, then the loop doesn't proceed to the next hashmap,
and what concerns me even more is the fact that in my logcat, my program perhaps doesn't loop properly (not really sure though), my hashmap size is 2, and it loops only once.
Here is my logcat,
03-14 17:35:36.195: D/Location(32341): Arrive at compareData
03-14 17:35:36.195: D/Status(32341): Total Finished List 2
03-14 17:35:36.195: D/Status(32341): Total Unfinished List 4
03-14 17:35:36.195: D/Status(32341): Inside Looping FinishedList, Looping 1
03-14 17:35:36.195: D/Status(32341): Inside Looping UnfinishedList, Looping ke 1
03-14 17:35:36.195: D/Status(32341): 21 is equal 21
03-14 17:35:36.195: D/Location(32341): Attempt to remove Fffgggh
03-14 17:35:36.195: D/Status(32341): Inside Looping UnfinishedList, Looping ke 2
03-14 17:35:36.195: D/Status(32341): 21 is not equal 44
03-14 17:35:36.195: D/Status(32341): Inside Looping UnfinishedList, Looping ke 3
03-14 17:35:36.195: D/Status(32341): 21 is not equal 46
03-14 17:35:36.195: D/Status(32341): Inside Looping UnfinishedList, Looping ke 4
03-14 17:35:36.195: D/Status(32341): 21 is not equal 48
03-14 17:35:36.195: D/Status(32341): Inside Looping FinishedList, Looping 2
03-14 17:35:36.195: D/Status(32341): Inside Looping UnfinishedList, Looping ke 5
03-14 17:35:36.195: D/Status(32341): 46 is not equal 21
03-14 17:35:36.195: D/Status(32341): Inside Looping UnfinishedList, Looping ke 6
03-14 17:35:36.195: D/Status(32341): 46 is not equal 44
03-14 17:35:36.195: D/Status(32341): Inside Looping UnfinishedList, Looping ke 7
03-14 17:35:36.195: D/Status(32341): 46 is equal 46
03-14 17:35:36.195: D/Location(32341): Attempt to remove Mau Coba Ah
03-14 17:35:36.195: D/AndroidRuntime(32341): Shutting down VM
03-14 17:35:36.195: W/dalvikvm(32341): threadid=1: thread exiting with uncaught exception (group=0x41a60c08)
03-14 17:35:36.200: E/AndroidRuntime(32341): FATAL EXCEPTION: main
03-14 17:35:36.200: E/AndroidRuntime(32341): Process: com.thesis.teamizer, PID: 32341
03-14 17:35:36.200: E/AndroidRuntime(32341): java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
03-14 17:35:36.200: E/AndroidRuntime(32341): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
03-14 17:35:36.200: E/AndroidRuntime(32341): at java.util.ArrayList.remove(ArrayList.java:403)
03-14 17:35:36.200: E/AndroidRuntime(32341): at com.thesis.teamizer.ViewTaskToDoList.compareData(ViewTaskToDoList.java:180)
03-14 17:35:36.200: E/AndroidRuntime(32341): at com.thesis.teamizer.ViewTaskToDoList$AttemptGetTodolist.onPostExecute(ViewTaskToDoList.java:708)
03-14 17:35:36.200: E/AndroidRuntime(32341): at com.thesis.teamizer.ViewTaskToDoList$AttemptGetTodolist.onPostExecute(ViewTaskToDoList.java:1)
03-14 17:35:36.200: E/AndroidRuntime(32341): at android.os.AsyncTask.finish(AsyncTask.java:632)
03-14 17:35:36.200: E/AndroidRuntime(32341): at android.os.AsyncTask.access$600(AsyncTask.java:177)
03-14 17:35:36.200: E/AndroidRuntime(32341): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
03-14 17:35:36.200: E/AndroidRuntime(32341): at android.os.Handler.dispatchMessage(Handler.java:102)
03-14 17:35:36.200: E/AndroidRuntime(32341): at android.os.Looper.loop(Looper.java:146)
03-14 17:35:36.200: E/AndroidRuntime(32341): at android.app.ActivityThread.main(ActivityThread.java:5602)
03-14 17:35:36.200: E/AndroidRuntime(32341): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 17:35:36.200: E/AndroidRuntime(32341): at java.lang.reflect.Method.invoke(Method.java:515)
03-14 17:35:36.200: E/AndroidRuntime(32341): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
03-14 17:35:36.200: E/AndroidRuntime(32341): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
03-14 17:35:36.200: E/AndroidRuntime(32341): at dalvik.system.NativeStart.main(Native Method)
could you please help me to find the answer, or even the right code?
And Line 180 is hashMapFixFinishedList.remove(i);
Thank you in advance..