Hi All,
I have for the last few days been trying to solve this challenging problem, can anyone help me?
I have downloaded the Datanucleus JDO tutorial and it works fine the standard Java standalone environment. However, upon integrating it with my STS/Spring Webflow/Tomcat application, a NULL pointer exception is thrown as it progresses through the Products list.
The relevant part of my code is as follows:
...Upon iterating through the Products list, it displays the first product (as there is only one product), but for some reason when the code loops back up to iter.hasNext(), it should exit, however it tries to receive the next (non-existent) product in the list. As mentioned above, in the standalone Java version, this works fine without exceptions!!Code:// Usual setup and then... pm = pmf.getPersistenceManager(); tx = pm.currentTransaction(); try { tx.begin(); LOGGER.debug("Executing Query for ALL Products..."); Query q=pm.newQuery("SELECT FROM " + Product.class.getName()); List<Product> products = (List<Product>)q.execute(); Iterator<Product> iter = products.iterator(); // Problem is here... upon the second iteration it should exit loop, but for some reason it doesn't... while (iter.hasNext()) { Product p = iter.next(); LOGGER.debug("> " + p); // upon second iteration, a NULL pointer exception is thrown if (p instanceof Book) { Book b = (Book)p; b.setDescription("This book has been reduced in price!"); } } tx.commit(); } finally { if (tx.isActive()) { tx.rollback(); } pm.close(); } LOGGER.debug("Query completed."); // And so on...
Any ideas or directions will be most helpful as I have run out of ideas on how to fix this problem.
For those who may want to see the exception report:
Please note that both the standalone Java application and the Spring Webflow/Tomcat application used Java 1.6.Code:07-Jul-2012 21:53:28 org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [accountapp] in context with path [/accountapp] threw exception [Request processing failed; nested exception is org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@1c5a33b targetAction = [EvaluateAction@5facbd expression = accountappFlowActions.submitGetAccount(requestParameters.getAccountId, manager), resultExpression = account], attributes = map[[empty]]] in state 'accountList' of flow 'adminmenu' -- action execution attributes were 'map[[empty]]'] with root cause java.lang.NullPointerException


Reply With Quote
