ItemizedOverlay + ArrayIndexOutOfBoundsException
<p>I want to display Geopoints to mapview which get geopoints dynamic from database. and my database updated frequently so Geopoints updated frequently too. and I get an error ArrayIndexOutOfBoundsException when clicking an point. I have read many forum giving soluton to fix is adding two code lines  setLastFocusedIndex(-1);  populate(); but I still get error. Can any one help me solv this problem?
Thanks
    public class PlacesItemizedOverlay extends ItemizedOverlay {</p>

<pre><code>MapController mc;
private int ind;
Direct_NewsLeft_DetailActivity direct;   
    View viewArticle;
    LayoutInflater li;
    private List&lt;GeoPoint&gt; mItems;  
    private List&lt;Drawable&gt; mMarkers;
    private Context mContext;

    TextView txtBrief;
    TextView txtDetail;
    RelativeLayout show_article;
    public static RelativeLayout display_list_articles_for_one_point, show_list_articles;
    CarteActivity cartActivity;

    public PlacesItemizedOverlay(Context context, Drawable marker, boolean shadow, LayoutInflater l) {
        super( boundCenterBottom(marker));
        mContext = context;
        li = l;
        setLastFocusedIndex(-1);  
    }

    public void setItems(ArrayList&lt;GeoPoint&gt; items, ArrayList&lt;Drawable&gt; drawables, boolean shawdow) {
        mItems = items;
        mMarkers = drawables; 
        setLastFocusedIndex(-1);
        populate();
    }

    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow)
    {
        if(!shadow)
        {
            super.draw(canvas, mapView, false);
            setLastFocusedIndex(-1);
            populate();
        }
    }   


    public void clear() {
        mItems.clear();
        setLastFocusedIndex(-1);
        populate();
    }


    @Override
    protected OverlayItem createItem(int i) {
        OverlayItem item = new OverlayItem(mItems.get(i), null, null);
        item.setMarker( boundCenterBottom(mMarkers.get(i)) );

        return item;
   }

    @Override
    public int size() {

        return mItems.size();   
    }


    public boolean onTap (final GeoPoint p, final MapView mapView){
        boolean tapped = super.onTap(p, mapView);

                        if (tapped){     

                            try{

                        //  int soBip=France24Activity.bitmapArticles.size();
                      //here to get latitude and longtitude value from mapview              
                            String latitude=Global.gListGeoLocAllForTimeline.get(ind).getLatitude();
                            String longtitude=Global.gListGeoLocAllForTimeline.get(ind).getLongitude();
                            Global.country=Global.gListGeoLocAllForTimeline.get(ind).getCountry();
                            cartActivity.showMultiArticles(latitude, longtitude);
                            setLastFocusedIndex(-1);
                            populate();

                            int test1=Global.gListTextTitleArticleForOnePointList.size();
                            for(int i=0;i&lt;test1;i++) {
                            //  Toast.makeText(mContext, "So bai bao la: "+test1+" title: " +Global.gListTextTitleArticleForOnePointList.get(i), Toast.LENGTH_LONG).show();
                            //Toast.makeText(mContext, "So bipmap la: "+    soBip,Toast.LENGTH_SHORT).show();       
                            }


                            try
                            {

                                if(test1==1) {
                                    setLastFocusedIndex(-1);
                                    populate();
                                    int test12=Global.gListTextTitleArticleForOnePointList.size();
                                    //Toast.makeText(mContext, "So bai bao la: "+test12, Toast.LENGTH_LONG).show();
                                cartActivity.showBackArticle();
                                viewArticle = li.inflate(R.layout.map_show_article, null);              
                                France24Activity.main_of_main_center.addView(viewArticle);  
                                show_article =(RelativeLayout)viewArticle.findViewById(R.id.map_show_article);
                                AnimLeftRight leftRight = new AnimLeftRight(show_article, 0);               
                                leftRight.setLayoutAnim_slideleftfromright(show_article, mContext);
                                Button imgBack=(Button)viewArticle.findViewById(R.id.backToMap);

                                WebView webview = (WebView)viewArticle.findViewById(R.id.webId); 
                                webview.loadData(
                                    "&lt;style type=\"text/css\"&gt;#image {margin-right:10px;}&lt;/style&gt;&lt;font COLOR=#0099FF&gt;&lt;h4&gt;"
                                            //+ Global.gListTextNewsArticlesWithNoNullGeo.get(ind)
                                            //+ Global.gListGeoLocAll.get(ind).getTitle()
                                            +Global.gListTextTitleArticleForOnePointList.get(0)
                                            + "&lt;/h4&gt;&lt;/br&gt;&lt;/font&gt;" 
                                            + "&lt;img src=\""
                                            //+ Global.gListImageJsonBigArticles.get(ind)
                                            //+ Global.gListGeoLocAll.get(ind).getImage()

                                            + Global.gListImageJsonBigArticleForOnePointList.get(0)
                                            + "\" align=\"left\" id=\"image\" \"&gt;"
                                            //+ Global.gListTextNewsBodyArticlesWithNoNullGeo.get(ind)
                                        //  + Global.gListGeoLocAll.get(ind).getNewsBody()
                                            + Global.gListTextNewsBodyArticleForOnePointList.get(0)
                                            + "&lt;img src=\"file:///android_res/drawable/flagmap.png"
                                            + "&gt;"
                                            ,     
                                    "text/html", "utf-8"
                                    );
                            //webview.setPadding(50, 0, 0, 0);

                                show_article.addView(webview);    
                                show_article.addView(imgBack);      


                                //cartActivity.backMapView.setVisibility(View.VISIBLE);


                                imgBack.setOnClickListener(new OnClickListener() {

                                @Override
                                public void onClick(View arg0) {
                                    // TODO Auto-generated method stub
                                //  Toast.makeText(mContext, "Test Click Here", Toast.LENGTH_SHORT).show();

                                }
                            });

                            }


                            else if(test1&gt;1)

                            { 
                                 try{

                                    int test2=Global.gListImageJsonBigArticleForOnePointList.size();
                                    for(int i=0;i&lt;test2;i++) {
                                    //Toast.makeText(mContext, "bipmap : "+i+   " la  : "+Global.gListImageJsonBigArticleForOnePointList.get(i),Toast.LENGTH_SHORT).show();         
                                    }

                                viewArticle = li.inflate(R.layout.display_list_articles_for_one_point, null);               
                                France24Activity.main_of_main_center.addView(viewArticle);
                                display_list_articles_for_one_point =(RelativeLayout)viewArticle.findViewById(R.id.list_articles);
                                cartActivity.showListviewOfArticles();  



                                    ListView list=(ListView)viewArticle.findViewById(R.id.showart);  
                                    ArrayList&lt;ListOfArticleForOneLocation&gt; listArticle = new ArrayList&lt;ListOfArticleForOneLocation&gt;();
                                    ListOfArticleForOneLocation article;

                                    try{
                                        for (int i=0;i&lt;Global.gListTextTitleArticleForOnePointList.size();i++) { 
                                            article = new ListOfArticleForOneLocation(Global.country,Global.gListTextTitleArticleForOnePointList.get(i),i);
                                            listArticle.add(article);
                                        }
                                        CustomAdapter lvAdapter =  new CustomAdapter(mContext, listArticle);
                                        list.setAdapter(lvAdapter);
                                        list.setOnItemClickListener(new OnItemClickListener()  

                                            {
                                            public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1,int arg2, long arg3) 
                                                {
                                                    cartActivity.showBackArticle();
                                                    cartActivity.hideListviewOfArticles();
                                            //  Toast.makeText(mContext, "You clicked on "+arg2, Toast.LENGTH_LONG).show();
                                                viewArticle = li.inflate(R.layout.show_list_articles, null);                
                                                France24Activity.main_of_main_center.addView(viewArticle);  
                                                show_list_articles =(RelativeLayout)viewArticle.findViewById(R.id.show_list_articles);

                                                AnimLeftRight leftRight = new AnimLeftRight(show_list_articles, 0);             
                                                leftRight.setLayoutAnim_slideleftfromright(show_list_articles, mContext);

                                                WebView webview = new WebView(mContext);

                                                //WebView webview = (WebView)viewArticle.findViewById(R.id.webforListArticle); 
                                                webview.loadData(
                                                    "&lt;style type=\"text/css\"&gt;#image {margin-right:10px;}&lt;/style&gt;&lt;font COLOR=#0099FF&gt;&lt;h4&gt;"
                                                            + Global.gListTextTitleArticleForOnePointList.get(arg2)
                                                            + "&lt;/h4&gt;&lt;/br&gt;&lt;/font&gt;"
                                                            + "&lt;img src=\""
                                                            + Global.gListImageJsonBigArticleForOnePointList.get(arg2)
                                                            + "\" align=\"left\" id=\"image\" \"&gt;"

                                                            + Global.gListTextNewsBodyArticleForOnePointList.get(arg2),
                                                    "text/html", "utf-8");    


                                        show_list_articles.addView(webview);    
                                } 

                            });  } catch(NullPointerException e2) { 

                            }


                            }catch(Exception e1) {
                                Toast.makeText(mContext, e1.toString() , Toast.LENGTH_LONG).show();
                            }
                            }
                            else { 

                                //  Toast.makeText(mContext, "Error to get indext" , Toast.LENGTH_LONG).show();


                            }

                                //end else here

                            }
                            catch (Exception e) {
                                // TODO: handle exception
                                //Toast.makeText(mContext, e.toString() , Toast.LENGTH_LONG).show();
                            }


                        }   catch(IndexOutOfBoundsException e) {Toast.makeText(mContext, e.toString() , Toast.LENGTH_LONG).show(); }
                            try {
                                finalize();
                            } catch (Throwable e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        } 
        else{
            //do what you want to do when you DONT hit an item
            }                   
        return true;
    }


    public boolean onTap(int i) { 
        ind=i;
        setLastFocusedIndex(-1);
        populate();

        return true;
    }   
</code></pre>

<p>}</p>
