java - asynctask not getting arraylist when called from a handler -


i'm using handler start asynctask when doing so, application crashes. reason stuck because if start asynctask via else (eg. onclicklistener) can run many times, on , on again, , works perfect every single time. execute asynctask handler, crashes application nullpointerexception.

my handler looks this

  public handler handler = new handler() {     @override     public void handlemessage(message msg) {       super.handlemessage(msg);         handler.post(new runnable() {           @override           public void run() {             new sortnearby().execute();           }          });     }   }; 

here part of stack trace application showing exception

caused by: java.lang.nullpointerexception @ badams.android.app.fragments.mainmenu_nearbyfragment$sortnearby.doinbackground(mainmenu_nearbyfragment.java:100) 

line 100 of code first line in asynctask under doinbackground

protected string doinbackground(string... args) {   (int = 0; < global.places.size(); i++) { //this line 100 

i understand exception more coming "global.places.size()" being null, stuck on why doing when called handler, works fine if start task other section of code.

edit

as requested @raghunandan, here entire code block doinbackground in asynctask, calculates distance between "place" , user:

class sortnearby extends asynctask<string, place, string> { protected string doinbackground(string... args) {   (int = 0; < global.places.size(); i++) { //this line 100     location locationa = new location("place");     locationa.setlatitude(global.places.get(i).getlatitude());     locationa.setlongitude(global.places.get(i).getlongitude());     location locationb = new location("user");     locationb.setlatitude(global.applicationlocationmanager.getlatitude());     locationb.setlongitude(global.applicationlocationmanager.getlongitude());     float dist = locationa.distanceto(locationb);     dist = dist / 1000;     global.places.get(i).setdistance(dist);   }   return null; } 

edit 2

global class extending application , defined in activity so:

global = (applicationglobal) getactivity().getapplicationcontext(); 

if nullpointerexception @ line 100 either global or global.places returning null.

did try debugging same?

debugging follow happening.

also handler not see how doinbackground method gets called?

where global variable defined? , when gets initialized?


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -