0

I am trying to make this simple function:

private void getID(){
    for(int i=0;i<crops.size();i++){
        ID.add(i);
    }
}

where cropps.size() is the size of a bitmaparraylist which i've made. People told me that these function fail because you can get the argument null. But how can i get null if i don't fill in any arguments...

I've also tried to make the input of the function an Arraylist of integers but this failed as wel. On my Oncreate method i use getID() after i made the crops so that isn't the error as well. So i'm kind of confused here and help would be much appreciated.

Kees

atish shimpi
  • 4,873
  • 2
  • 32
  • 50
Kees Til
  • 171
  • 1
  • 17
  • 1
    If you get a NPE, `crops` or `ID` can be null. Without seeing if you initialize them well we can't tell you what's causing the failure. – Alexis C. Dec 06 '14 at 11:43
  • 1
    See also: http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – Alexis C. Dec 06 '14 at 11:46
  • @ZouZou, my ID list is an empty arraylist but that doen't mean its null right? – Kees Til Dec 06 '14 at 11:50
  • No if you initialize it well, it shoudln't be null. However, crops can be null. Follow the stacktrace, see at which line this error is coming, this will tell you what is null. – Alexis C. Dec 06 '14 at 11:52
  • @ZouZou, thanks :), it says it gets the error in the line where ID.add(i); occurs So ID should be null, but i defined ID as: ArrayList ID; Is the problem maybe that i should change that in: ArrayList ID = new ArrayList(); – Kees Til Dec 06 '14 at 11:59
  • 1
    Yes `ArrayList ID` declares ID as an ArrayList of Integer, but it doesn't mean that it's initialized. declaration != initialization !!! – Alexis C. Dec 06 '14 at 12:00

0 Answers0