I need for my app this int[] format as I wrote in the title.
I'm fetching the value out of a HashMap which is filled out of an XML file with this format [00, 00, 00, 00], but I need it for every int with 0xin front.
I tried to "convert" it via a for-loop:
for(int i = 0; i < value.length; i++){
value[i] = "0x" + value[i];
}
but I cant convert from String to int this way.
Then I tried to change it directly in the XML file, but then my app crashes with an NPE.
Now I want to know if there is a solution to my problem.
EDIT:
For further explanation:
I tried this before, but it did not work:
public int[] getValue(Map map, String key) {
Map keyMap = map;
int[] value = {};
@SuppressWarnings("rawtypes")
Iterator iter = keyMap.entrySet().iterator();
while (iter.hasNext()) {
@SuppressWarnings("rawtypes")
Map.Entry mEntry = (Map.Entry) iter.next();
if (mEntry.getKey().equals(key)) {
value = (int[]) mEntry.getValue();
}
}
return value;
}
Then I tried one of the answers and added
for(int i = 0; i < value.length; i++){
value[i] = Integer.valueOf(String.valueOf(value[i]), 16);
}
before the return. Now it works... but I dont know why it works :(
int[] int = {0x00, 0x00, 0x00, 0x00}intisint- hexadecimal prefixes are only for interpretation and not for calculation.int[] a = {0x00, 0x00, 0x00, 0x00}andint[] a = {0,0,0,0}value[i] = Integer.valueOf(String.valueOf(value[i]), 16);works in general. The problem is that you already have a wrong value when you read the XML, sometimes even aNumberFormatException. You cannot repair that after the fact.