0

オン* productIdList.add(p.getId()); * この行には、別のメソッドで定義された内部クラス内の非最終変数 productIdlist を参照できません。

コードは次のとおりです。

public ArrayList<String> getProductData() {


    ArrayList<String> productIdList = new ArrayList<String>();

    new Thread(new Runnable() {

        public void run() {
            HttpClient httpclient= new DefaultHttpClient();
            GeneralConstans GC = new GeneralConstans();
            // Products will be stated in memory
            HttpPost httpget = new HttpPost(GC.UrlConstants);
            HttpResponse response;
            String result = null;
            try {

                HttpContext ctx = new BasicHttpContext();

                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
                        2);
                httpget.setEntity(new UrlEncodedFormEntity(nameValuePairs,
                        "UTF-8"));

                response = httpclient.execute(httpget, ctx);
                HttpEntity resEntity = response.getEntity();

                if (resEntity != null) {
                    result = EntityUtils.toString(resEntity);
                    JSONArray arr = new JSONArray(result);
                    Gson gson = new Gson();
                    if (arr.length() > 0) {
                        for (int j = 0; j < arr.length(); j++) {
                            Product p = gson.fromJson(arr.getString(j),
                                    Product.class);
                            productIdList.add(p.getId());
                        }                       

                    }

                }

            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (SocketException e) {
                /*if (checkAbortStatus(e.getMessage()) == true) {
                    handler.sendEmptyMessage(0);
                }*/
            } catch (IOException e) {
                /*if (checkAbortStatus(e.getMessage()) == true) {
                    handler.sendEmptyMessage(0);
                }*/
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }


        }

        private Handler handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {

                super.handleMessage(msg);
            }
        }; 

    }).start();
    return productIdList;

何が問題なのですか?どうすれば修正できますか?前もって感謝します。

4

1 に答える 1