-1
new AsyncTask<Ticket, Void, List<TPVLine>>() {
        @Override
        protected List<TPVLine> doInBackground(Ticket... params) {
            List<TPVLine> lines;
            while (true){
                Log.d(TAG, "Waiting for data base response");
                try {
                    lines = params[0].getLines();
                    Log.d(TAG, "Data base response completed");
                    break;
                }catch (SQLiteException | NullPointerException ex){
                    ActiveAndroid.clearCache();
                    Log.d(TAG, "Cleaning cache");
                    Log.wtf(TAG, ex.toString());
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            }
            return lines;
        }

        @Override
        protected void onPostExecute(List<TPVLine> aVoid) {
            super.onPostExecute(aVoid);
            linesTPV = new ArrayList<TPVLine>();
            if (aVoid != null){
                linesTPV = aVoid;
            }
            linesTPV.addAll(noSavedLines);
            mainActivity.getTpvFragment().resetPrice();
            notifyDataSetChanged();
            if (linesTPV.size() == 0){
                mainActivity.getTpvFragment().getListContainer().setVisibility(View.INVISIBLE);
                mainActivity.getTpvFragment().getMessageContainer().setVisibility(View.VISIBLE);
            }else {
                mainActivity.getTpvFragment().getListContainer().setVisibility(View.VISIBLE);
                mainActivity.getTpvFragment().getMessageContainer().setVisibility(View.INVISIBLE);
            }
            notifyDataSetChanged();
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, mainActivity.getCurrentTicket());

This are the calls, first in Ticket.java

public List<TPVLine> getLines() {
    return new Select().from(TPVLine.class).where("Ticket = ?", this.getId()).execute();
}

The second is in TPVLine.java

public static List<TPVLine> getLines(Ticket ticket){
    return new Select().from(TPVLine.class).where("Ticket = ?", ticket.getId()).orderBy("Id ASC").execute();
}

The issue is caused when i call TPVLine.class, i make sure first that Ticket != null. I'm using ActiveAndroid to manage the database

Kevin Lopez
  • 63
  • 1
  • 9
  • Did you read the fancy manual: https://developer.android.com/reference/android/os/AsyncTask.html? Because if I read correctly your code, `params[0]` is obviously `null` –  May 18 '16 at 12:22
  • Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) –  May 18 '16 at 12:24
  • The problen ins't params[0], i pass a ticket and it is't null. The problem is a null pointer exception caused by call the method .getClass() on a null object, and i only use the .class or .getClass() in database calls – Kevin Lopez May 18 '16 at 14:49
  • Maybe you should add a logstash output then –  May 18 '16 at 17:11

1 Answers1

1

you are returning null instead of lines in your asynctask doInBackground event.

return lines;
KDeogharkar
  • 10,939
  • 7
  • 51
  • 95