0

doInBackground()当我的程序在方法中时,我正在从 JSON API 中检索一些数据,doInBackground()我的日志指示数据已被检索,但不是去,而是onPostExecute()仍在doInBackground()无限循环中运行。我怎样才能停止那个循环?

这是我的doInBackground()编码:

@Override
protected String doInBackground(String... DATA) {
    // TODO Auto-generated method stub
    TYPE = DATA[0];

if(TYPE=="reservation_page")
    {
        URL = DATA[1];
        jParser = new JsonParser();
        json = jParser.getJSONfromUrl(URL+memberId);
        try
        {
            JSONArray reservation = json.getJSONArray(TAG_RSVTION);
            for(int i = 0; i<reservation.length(); i++)
            {
                JSONObject r = reservation.getJSONObject(i);
                amount = r.getString(TAG_AMNT);
                gcpamount = r.getString(TAG_GCPAMNT);
                date1 = r.getString(TAG_DATE);
                month = r.getString(TAG_MNTH);
                year = r.getString(TAG_YEAR);
                time1 = r.getString(TAG_TIME);
                golfcourse_name = r.getString(TAG_GLFCRSNAME);
                no_of_player = r.getString(TAG_PLYRNO);

                HashMap<String, String> map = new HashMap<String, String>();

                map.put(TAG_AMNT, amount);
                map.put(TAG_GCPAMNT, gcpamount);
                map.put(TAG_DATE, date1);
                map.put(TAG_MNTH, month);
                map.put(TAG_YEAR, year);
                map.put(TAG_TIME, time1);
                map.put(TAG_GLFCRSNAME, golfcourse_name);
                map.put(TAG_PLYRNO, no_of_player);

                resvList.add(map);
                Log.v(TAG_LOG, "list: "+resvList);
            }
            Log.v(LoadingScreen.TAG_LOG, "reserv: "+reservation);
            Log.v(LoadingScreen.TAG_LOG, "name: "+golfcourse_name);
        }
        catch(JSONException e)
        {
            Log.v(LoadingScreen.TAG_LOG, String.valueOf(e));
        }
    }
    return null;
}

这是我的onPostExecute()编码:

protected void onPostExecute(String result) {
    // TODO Auto-generated method stub
    super.onPostExecute(result);

if(TYPE=="reservation_page")
    {
        Intent in = new Intent(context, MyReservation.class);
        in.putExtra(TAG_MBRID, memberId);
        in.putExtra(TAG_AMNT, amount);
        in.putExtra(TAG_GCPAMNT, gcpamount);
        in.putExtra(TAG_DATE, date1);
        in.putExtra(TAG_DAY, day);
        in.putExtra(TAG_MNTH, month);
        in.putExtra(TAG_YEAR, year);
        in.putExtra(TAG_TIME, time1);
        in.putExtra(TAG_GLFCRSNAME, golfcourse_name);
        in.putExtra(TAG_PLYRNO, no_of_player);
        context.startActivity(in);
    }
    progress.dismiss();
}
4

2 回答 2

2

等等等等等等...

你的if 条件是错误的..它应该像,

if(TYPE.equals("reservation_page"))

不是

if(TYPE=="reservation_page")

用于.equals()比较String Class两个字符串..

于 2012-08-18T19:14:27.263 回答
1

您是否甚至进入了循环,或者可能jParser.getJSONfromUrl(URL+memberId)永远等待来自您的 URL 的响应?只需运行您的调试器,找出问题所在应该不是问题。

于 2012-08-18T19:55:39.693 回答