0

I have some values i have stored in mysal table. basically, they are some strings that hold the value up or down.

I want to fetch the data in my table and compare if they are equal to up or down

This is the code

String up = "up";
String down = "down";

@SuppressWarnings("deprecation")
Query query = currentSession.createSQLQuery(
           "select * from trades where trade_session_status=:trade_session_status AND trade_profit_worker_status=:trade_profit_worker_status");
query.setParameter("trade_session_status", "DONE");
query.setParameter("trade_profit_worker_status", "UNDONE");
@SuppressWarnings("rawtypes")
List < Object[] > result = query.list();

for (Object[] objects: result) {
Integer id = (Integer) objects[0];
String trade_prediction = (String) objects[10];
String trade_result = (String) objects[11];


if(trade_prediction.equals(up) && trade_result.equals(up)) {
}

The code works and i can test if the strings are equal but somewhere down the line, i get an error on this line

if(trade_prediction.equals(up) && trade_result.equals(up)) {

but the program still works.

I get this error

SEVERE: Unexpected error occurred in scheduled task. java.lang.NullPointerException at com.boilerplate.components.Scheduler.profit_cron(Scheduler.java:396)

This is the line 396

if(trade_prediction.equals(up) && trade_result.equals(up)) { }

What could be causing the error?

Gandalf
  • 1
  • 29
  • 94
  • 165
  • objects[10] in your for loop seems to be null due to which trade_prediction will be null causing NPE – Pushpesh Kumar Rajwanshi Nov 11 '18 at 19:39
  • The whole point of using a database is to be able to execute queries to find what you want. Loading the whole table into memory to loop through every row is exactly what you shouldn't do. Not to mention the use of SQL instead of JPQL – JB Nizet Nov 11 '18 at 19:40

0 Answers0