Domanda

i tried to store a bytearray in a LinkedHashMap

static Map<Long, byte[]> lhm2 = new LinkedHashMap<Long, byte[]>(1000);

But

lhm2.get(1)

will throw a NullPointerException. lhm2 contains key 1 and i checked if it's not null with

if(lhm2.get(1) != null){
    System.out.println("not null");
}

Any suggestions?

Thanks in advance!

Chris

È stato utile?

Soluzione

your key should be a long so better do this

lhm2.get(1L)

instead of doing like

lhm2.get(1)

Altri suggerimenti

You should do:

if(lhm2.contains(1){
    lhm2.get(1)
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top