Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

ConcurrentModificationException  RSS feed

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got this error java.util.ConcurrentModificationException
how to solved this problem

package com.gate;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ConcurrentModificationException;

import android.R.integer;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

public class MainEdtShifting extends Activity {

private Button btnexit,btnback,btnSearch,BtnSave,BtnReset;
ProgressDialog pDialog;
JSONArray dataJSON = null;
ArrayList<SetterGetter> tampung ;
ArrayList<SetterGetter> tampungdetail ;
ArrayList<SetterGetter> tampungspin ;
AutoCompleteTextView txtNoContainer ;
DataAdapter adapter;
static EditText EdtTglShiftting;
private int hit;
EditText txtBlock,txtRow,txtCol,txtStack ;
EditText txtBlock1,txtRow1,txtCol1,txtStack1 ;
ListView lv;

private static final String url_update_container = "http://192.168.10.91/gate_app/get_cek_update.php";
private static final String TAG_NoContainer = "NoContainer";
private static final String TAG_Block = "Block";
private static final String TAG_Row = "Row";
private static final String TAG_Col = "Col";
private static final String TAG_Stack = "Stack";
private static final String TAG_SUCCESS = "success";
private static final String TAG_userlogin = "userlogin" ;
private int success = 0 ;

private String userlogin;
private Spinner spinner_condition ;

@Override
   protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
       setContentView(R.layout.frmeditshifting);
       
       Intent dapatdata = this.getIntent();
userlogin = dapatdata.getStringExtra("userlogin");

tampung = new ArrayList<SetterGetter>();
txtNoContainer = (AutoCompleteTextView) findViewById(R.id.txtNoContainer);
       txtNoContainer.requestFocus();
       new GetDataKontainer().execute();
       
}

public class GetDataKontainer extends AsyncTask<String, String, String> {
 @Override
 protected void onPreExecute() {
  super.onPreExecute();
  pDialog = new ProgressDialog(MainEdtShifting.this);
  pDialog.setMessage("Loading Data...");
  pDialog.setIndeterminate(false);
  pDialog.setCancelable(false);
  pDialog.show();
 }

 @Override
 protected String doInBackground(String... arg0) {    
 
 String url = "http://192.168.10.91/gate_app/get_cek_shifting_search.php?cont_number=" ;
 Log.e("proses : ", "---------->" + url);
 
 JSONParser jParser = new JSONParser();
 JSONObject json = jParser.getJSONFromUrl(url);
 
 System.out.println(" tampung --------------> " + tampung);
 tampung.clear();
 
  try {
  dataJSON = json.getJSONArray("list_container");
  System.out.println(" kesini --------------> ");
  for (int i = 0; i < dataJSON.length(); i++) {
JSONObject c = dataJSON.getJSONObject(i);

tampung.add(new SetterGetter(c.getString("cont_number"), c.getString("block_loc"), c.getString("rowss"), c.getString("col"), c.getString("stack"), "",c.getString("contstatus"))) ;

  }

 
  } catch (JSONException e) {
   
  }
 
  return null;
 }
 
 @Override
 protected void onPostExecute(String result) {  
super.onPostExecute(result);  
pDialog.dismiss();  

List<SetterGetter> list = new ArrayList<SetterGetter>();

       for(SetterGetter karyawan:tampung){
        list.add(new SetterGetter(karyawan.getcontno().toString(), karyawan.getblock().toString(), karyawan.getrow().toString(), karyawan.getcol().toString(), karyawan.getstack().toString(),"",karyawan.getcontstatus().toString())) ;
       
        Iterator<SetterGetter> iter = list.iterator();
       
        try{
       
        while(iter.hasNext()){
        SetterGetter str = iter.next();
       
        String AA = karyawan.getcontno().toString(); String BB = karyawan.getblock().toString();
            String CC = karyawan.getrow().toString(); String DD = karyawan.getcol().toString();
            String EE = karyawan.getstack().toString(); String FF = karyawan.getcontstatus().toString();
           
           
            String KK = str.getcontno().toString(); String LL = str.getblock().toString();
            String MM = str.getrow().toString(); String NN = str.getcol().toString();
            String OO = str.getstack().toString(); String PP = str.getcontstatus().toString();
           
           
            if(KK.equals(AA) && LL.equals(BB) && MM.equals(CC) && NN.equals(DD) && OO.equals(EE) && PP.equals(FF)){
            iter.remove();
           }
        }
       
        list.add(new SetterGetter(karyawan.getcontno().toString(), karyawan.getblock().toString(), karyawan.getrow().toString(), karyawan.getcol().toString(), karyawan.getstack().toString(),"",karyawan.getcontstatus().toString())) ;
       
        }catch (ConcurrentModificationException e) {
        e.printStackTrace();  
}
       
       }
       
       txtNoContainer = (AutoCompleteTextView) findViewById(R.id.txtNoContainer);
       txtNoContainer.setThreshold(1);
       adapter = new DataAdapter(MainEdtShifting.this, R.layout.frmeditshifting, R.id.txtnocont, list);
       txtNoContainer.setAdapter(adapter);
       txtNoContainer.setText("") ;
       
       txtNoContainer.requestFocus();

 }
}

}
ConcurrentModificationException.jpg
[Thumbnail for ConcurrentModificationException.jpg]
 
Saloon Keeper
Posts: 5235
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem occurs in line 121 of the DataAdapter class, so we'd need to see the relevant part of that.

The relevant variable is probably the (not-too-well-named) "list", so you should start by examining where (and when) that is modified.
 
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!