setListAdapter unable to be resolved

Liam

a real amateur developer here in dire need of some assistance. I've been trying to parse JSON data and turn it into a list of items, but I am having difficulties attempting to use the setListAdapter method despite importing it into the class. Any help would be massively appreciated.

Here is my main activity, error is in the onPostExecute method

import java.io.IOException;
import java.util.List;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;

import android.app.Activity;
import android.net.http.AndroidHttpClient;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;


public class JSON extends Activity {

    // Coordinates used for centering the Map

    private final static String UNAME = "aporter";
    private final static String URL = "http://api.geonames.org/earthquakesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&username="
            + UNAME;

    public static final String TAG = "MapsEarthquakeMapActivity";

    // Set up UI and get earthquake data
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        new HttpGetTask().execute(URL);

    }

    private class HttpGetTask extends
            AsyncTask<String, Void, List<GeonameRec>> {

        AndroidHttpClient mClient = AndroidHttpClient.newInstance("");

        @Override
        protected List<GeonameRec> doInBackground(String... params) {

            HttpGet request = new HttpGet(params[0]);
            JSONResponseHandler responseHandler = new JSONResponseHandler();

            try {

                // Get Earthquake data in JSON format
                // Parse data into a list of EarthQuakeRecs

                return mClient.execute(request, responseHandler);

            } catch (ClientProtocolException e) {
                Log.i(TAG, "ClientProtocolException");
            } catch (IOException e) {
                Log.i(TAG, "IOException");
            }

            return null;

        }

        @Override
        protected void onPostExecute(List<GeonameRec> result) {

            if (null != mClient)
                mClient.close();
            setListAdapter(new ArrayAdapter<String>(
                 JSON.this,
                 R.layout.listitem, result));



        }
    }

}
}

And here is my class where I format the JSON response.

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.impl.client.BasicResponseHandler;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

public class JSONResponseHandler implements
    ResponseHandler<List<GeonameRec>> {
@Override
public List<GeonameRec> handleResponse(HttpResponse response)
        throws ClientProtocolException, IOException {
    List<GeonameRec> result = new ArrayList<GeonameRec>();
    String JSONResponse = new BasicResponseHandler()
            .handleResponse(response);
    try {
        JSONObject object = (JSONObject) new JSONTokener(JSONResponse)
                .nextValue();
        JSONArray earthquakes = object.getJSONArray("earthquakes");
        for (int i = 0; i < earthquakes.length(); i++) {
            JSONObject tmp = (JSONObject) earthquakes.get(i);
            result.add(new GeonameRec(
                    tmp.getDouble("lat"),
                    tmp.getDouble("lng")));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return result;
}

}
Mohammad Rahchamani

setListAdapter method is available in ListActivity not in Activity. to do so in an Activity sub class, you should define your ListView and call listView.setAdapter

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

이클립스 : getListView (). setListAdapter (mAdapter);

분류에서Dev

Android ListView- setListAdapter 및 getListAdapter 오류?

분류에서Dev

setListAdapter를 확인할 수 없습니다.

분류에서Dev

setlistadapter가 postexecute에서 작동하지 않습니다.

분류에서Dev

setListAdapter 메소드를 해결할 수 없습니다.

분류에서Dev

JSONObject cannot be resolved to a type

분류에서Dev

Block until promise is resolved

분류에서Dev

How are function calls resolved?

분류에서Dev

ListActivity의 Listview가 setListAdapter에서 ResourceNotFound 예외를 발생시킵니다.

분류에서Dev

조각에 대해 setListAdapter가 작동하지 않습니까? 모든 대안

분류에서Dev

Alpine Linux sometimes DNS is not resolved

분류에서Dev

Symbol not resolved error in Activity file

분류에서Dev

AngularJS route not resolved on page load

분류에서Dev

Banshee package dependencies cannot be resolved

분류에서Dev

Parametrized object cannot be resolved to variable

분류에서Dev

Looper.prepare ()를 호출하지 않은 스레드 내부에 핸들러를 생성 할 수 없음-setListAdapter

분류에서Dev

Unix: How to Test Ip Address is resolved to name

분류에서Dev

LiferayWindowState.EXCLUSIVE cannot be resolved to a type?

분류에서Dev

socket.io ERR_NAME_NOT_RESOLVED

분류에서Dev

NotificationManagerCompat Can't be resolved - Android Wear

분류에서Dev

jQuery multiple deferreds resolved and handled before return

분류에서Dev

ajax POST in .NET MVC 4 parameters are not resolved

분류에서Dev

Why I get cannot be resolved with maven project

분류에서Dev

ActionBarActivity cannot be resolved to a type, Jar mismatch : Eclipse

분류에서Dev

iptables resolved addresses differs from nslookup

분류에서Dev

When are function templates resolved in c++?

분류에서Dev

How to detect manually resolved conflicts in git

분류에서Dev

Ubuntu 17.04 systemd-resolved 구성

분류에서Dev

Q.1 CORDOVA_VERSION cannot be resolved or is not a field. Q.2 preferences cannot be resolved

Related 관련 기사

  1. 1

    이클립스 : getListView (). setListAdapter (mAdapter);

  2. 2

    Android ListView- setListAdapter 및 getListAdapter 오류?

  3. 3

    setListAdapter를 확인할 수 없습니다.

  4. 4

    setlistadapter가 postexecute에서 작동하지 않습니다.

  5. 5

    setListAdapter 메소드를 해결할 수 없습니다.

  6. 6

    JSONObject cannot be resolved to a type

  7. 7

    Block until promise is resolved

  8. 8

    How are function calls resolved?

  9. 9

    ListActivity의 Listview가 setListAdapter에서 ResourceNotFound 예외를 발생시킵니다.

  10. 10

    조각에 대해 setListAdapter가 작동하지 않습니까? 모든 대안

  11. 11

    Alpine Linux sometimes DNS is not resolved

  12. 12

    Symbol not resolved error in Activity file

  13. 13

    AngularJS route not resolved on page load

  14. 14

    Banshee package dependencies cannot be resolved

  15. 15

    Parametrized object cannot be resolved to variable

  16. 16

    Looper.prepare ()를 호출하지 않은 스레드 내부에 핸들러를 생성 할 수 없음-setListAdapter

  17. 17

    Unix: How to Test Ip Address is resolved to name

  18. 18

    LiferayWindowState.EXCLUSIVE cannot be resolved to a type?

  19. 19

    socket.io ERR_NAME_NOT_RESOLVED

  20. 20

    NotificationManagerCompat Can't be resolved - Android Wear

  21. 21

    jQuery multiple deferreds resolved and handled before return

  22. 22

    ajax POST in .NET MVC 4 parameters are not resolved

  23. 23

    Why I get cannot be resolved with maven project

  24. 24

    ActionBarActivity cannot be resolved to a type, Jar mismatch : Eclipse

  25. 25

    iptables resolved addresses differs from nslookup

  26. 26

    When are function templates resolved in c++?

  27. 27

    How to detect manually resolved conflicts in git

  28. 28

    Ubuntu 17.04 systemd-resolved 구성

  29. 29

    Q.1 CORDOVA_VERSION cannot be resolved or is not a field. Q.2 preferences cannot be resolved

뜨겁다태그

보관