[Solved] Null Pointer Except, but why? [closed]


I believe this line is wrong:

if(type.equals(null))
    strTypeList = "What?What?What?LOLOLOLOLOLnopechucktesta";

it should be:

if(type == null)
    strTypeList = "What?What?What?LOLOLOLOLOLnopechucktesta";

Without seeing the contents of the method calls here:

Type = AddyBook.get(x).getContactType();

it’ll be hard to debug but if I were to guess it would be the method “getContactType()” is returning null.

EDIT:

Try unchaining the calls:

Instead of:

Type = AddyBook.get(x).getContactType();
strType = Type.toString ( );

Try:

Entry entry; // I don't actually know what .get() returns
entry = AddyBook.get(x);
if (entry == null)
    throw new RuntimeException("entry is null at "+x+" book size="+AddyBook.size());

Type type = entry.getContactType();
if (type == null)
    throw new RuntimeException("type is null from entry="+entry.toString());

strType = Type.toString ( );

14

solved Null Pointer Except, but why? [closed]