0

我已经创建了两个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;
    }
}
4

1 回答 1

0

您未能初始化point_to_be_send
添加类似这样的内容

Geopoint point_to_be_send = new Geopoint(myDoubleI, myDoubleJ);

point_to_be_send is null这就是为什么你得到例外。

于 2013-01-08T01:30:14.740 回答