2 sachinks SachinKS 于 2013.01.08 13:25 提问

AsyncTask onPostExecute NullPointerException

创建了两个AsyncTask,但是当把第一个AsyncTask的输出当做输入传给第二个AsyncTask时,就会出现空值异常,第一个AsyncTask 是Geopoint。

String input=EnterYourSearch.getText().toString();
Geopoint point_to_be_send;
     get_location.execute(input);       
     getplaces.execute(point_to_be_send);
        public class Getlocation extends AsyncTask<String, String, Geopoint> 
        { 
          @Override
          protected Geopoint doInBackground(String... params) {
            jsonobject=JsonRequest.getLocationInfo(params[0]);   
            point=JsonRequest.getLatLong(jsonobject);     
            return point;    
          }
          @Override
          protected void onPostExecute( Geopoint point) {
            if(point.lat !=0)
            {
              //check=false;
              point_to_be_send=point;
            }
          }
        }
    public class Getplaces extends AsyncTask<Geopoint, String, Boolean>
        {
            @Override
            protected Boolean doInBackground(Geopoint... params) {
                // TODO Auto-generated method stub
                 googleplaces=new Googleplaces();
                       try {
                        googleplaces.search(params[0].lat, params[0].lon, 1000, null);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        Log.d("Error", e.toString());
                        e.printStackTrace();
                    }
                    return true;
                    }

Geopoint 类:

public class Geopoint {
    public double lat;
    public double lon;
    public Geopoint(double i, double j) {
        // TODO Auto-generated constructor stub
        lat=i;
        lon=j;
    }
}
Csdn user default icon
上传中...
上传图片
插入图片