AsyncTask onPostExecute NullPointerException

时间:2013-01-08 00:58:20

标签: android android-asynctask

我已经创建了两个AsyncTask但是当我传递第一个asyn任务的输出时,它是Geopoint作为第二个asyn任务的输入,它是null  这是我的代码。

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;
    }
}

1 个答案:

答案 0 :(得分:0)

您未能初始化point_to_be_send
添加这样的东西

Geopoint point_to_be_send = new Geopoint(myDoubleI, myDoubleJ);

point_to_be_send is null这就是你获得例外的原因。