0

I written an Java jms code to execute message and my problem is i have 10 records in the list it is processing first two records and from third record onwards not processing due to third record value is null, please help me how to skip the null message and proceed the for loop to process remaining records. Is it possible to do if any message is null skip and proceed. Thanks in Advance

My log shows in the else part record failure "null pointer exception" and come out of the loop further not proceed.

My Java code:

 for (createTestbean createTestBean : createTestbeanList) {             
                    String createTestMessage = createTestBean.getMessage();
   TextMessage textMessage = queueSession
                    .createTextMessage(createTestMessage);
TextMessage tm;                

 String replymessage = null ;
                String code = null;
            Message message = queueReceiver.receive(60 * 1000);
            if (message != null) {
                logger.info("Received message:\n" + message);
                 tm =(TextMessage) message;
                logger.info("Message:" + tm.getText()); 
                replymessage =tm.getText();
                } else {
                logger.info("No message received!\n");
                recordFailure(null);
            }
             code = replymessage.split(",")[2];
             createTestDAO rmdao = new createTestDAO();
             rmdao.updateCreateTest(replymessage,code);
            }
Maxtech
  • 111
  • 16
  • Please post the complete stacktrace and the related code/line presenting the error – nortontgueno Feb 11 '19 at 19:10
  • 1
    If `createTestBean.getMessage()` is the message that is `null`, check after `String createTestMessage = createTestBean.getMessage();`: `if (createTestMessage == null) continue;` – forpas Feb 11 '19 at 19:15
  • 2
    Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – ferpel Feb 11 '19 at 19:17
  • @forpas Thanks the issue solved – Maxtech Feb 11 '19 at 20:13

1 Answers1

0

You can accomplish this with the continue statement:

if (createTestBean == null)
    continue;

If creatTestBean is null, it will skip directly to the loop's update statement.

Vecna
  • 111
  • 2