java - Index out of bounds, but not? -


i have no idea how happening, maybe i'm missing simple.

i trying remove first index if exists code this:

arraylist<string> historyvalues = new arraylist<string>(); arraylist<string> historylabels = new arraylist<string>(); some_big_process_which_populates_array() if(historylabels.size() >= 1 && historyvalues.size() >= 1 ){     historylabels.add("not enough data yet");     historyvalues.add("0.0"); }else{     log.v("history_values", historyvalues.tostring());     historyvalues.remove(0);     historylabels.remove(0); } 

and error. how empty array getting past size() checks?

    06-18 15:36:53.208  1510815108/com.rainforestautomation.android.energyvue v/history_values﹕ [] 06-18 15:36:53.208  15108-15108/com.rainforestautomation.android.energyvue d/androidruntime﹕ shutting down vm 06-18 15:36:53.209  15108-15108/com.rainforestautomation.android.energyvue e/androidruntime﹕ fatal exception: main process: com.rainforestautomation.android.energyvue, pid: 15108 java.lang.indexoutofboundsexception: invalid index 0, size 0         @ java.util.arraylist.throwindexoutofboundsexception(arraylist.java:255) 

edit:

it appears reversed logic.

your comparison inverted.

if(historylabels.size() >= 1 && historyvalues.size() >= 1 ){ 

should

if(historylabels.size() < 1 && historyvalues.size() < 1 ){ 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -