Pessoas… se acaso não for a área própria para essa publicação me desculpem. Sou novo por aqui e também no Java. Estou com um grande problema. Assumi um projeto em andamento e está difícil acompanhar o andamento das coisas. Possuo uma aplicação que quando eu executo encontro o erro [System Exception] java.lang.NullPointerException. Já sei que é devido ao acesso à uma variável nula. Porém não estou conseguindo encontrar o motivo pelo qual ela está recebendo valor nulo. Minha classe é essa:
[i]@RuntimeClass(label=“SIMCardElement”)
public class SIMCardElement extends MessageElement {
// numero sim card
@RuntimeDescription(label="SimCard")
@RuntimeManaged(type=EType.CHAR_ARRAY, arraysize=20, dialogEditor=DefaultEditors.CHAR_ARRAY)
public String simcard;
/**
* construtor
*/
public SIMCardElement() {
super.ie = PACKED_DECIMAL;
super.moreflag = 0x00;
super.length = 0x00;
super.length = 0;
}
/**
* decodifica elemento
* @param buffer
* @throws continental.protocol.acp.base.ACPParserException
*/
@Override
public void parse(ByteBuffer buffer) throws ACPParserException {
super.parseSubHeader(buffer);
if (length > 0) {
byte[] binsimcard = new byte[super.length];
buffer.get(binsimcard);
simcard = BitHandler.getString(binsimcard, StringFormatOutput.Hex);
}
}
/**
* retorna bytes do elemento
* @param buffer
*/
@Override
public void toBytes(ByteBuffer buffer) {
byte[] bindata = BitHandler.getBytes(simcard, BytesFormatInput.Hex);
length = (int)bindata.length;
if (length > 0x1F)
moreflag = 0x01;
super.toBytesSubHeader(buffer);
buffer.put(bindata);
}
@Override
public int length() {
[b]return simcard.length() / 2;[/b]
}
}[/i]
O erro está justamente nesse return em destaque, pois como a variável simcard tem valor null, a divisão não ocorre. Qualquer ideia é bem vinda. Obrigado.