无法解析方法get(int)

时间:2015-11-17 10:29:05

标签: android horizontalscrollview

从服务器获得响应后我在整数数组中存储点,我试图在我的水平滚动视图中添加该数组,但它在我的循环中给出了错误,以下是我的代码可以有人帮忙吗?谢谢提前

此行附近的错误

tv.setText(points.get(i));

JAVA

 protected ArrayList<HashMap<String, String>> doInBackground(
                String... args) {
            ServiceHandler sh = new ServiceHandler();

            // Making a request to url and getting response

            String jsonStr = sh.makeServiceCall(PLACE_URL, ServiceHandler.GET);

            Log.d("Response: ", "> " + jsonStr);

            if (jsonStr != null) {
                try {
                   placejsonObj = new JSONArray(jsonStr);
                    // state_list = jsonObj.getJSONArray(COUNTRY_LIST);
                    // looping through All Contacts

                        jobject = placejsonObj.getJSONObject(0);
                        msgs=jobject.getString("user_status");

                        pointsarray=placejsonObj.getJSONArray(1);
                       // points=pointsarray.getString("point");
                    System.out.println("Kya yar" + "Failure"+pointsarray);
                    points = new int[pointsarray.length()];
                    for(int m=0; m<pointsarray.length(); m++) {
                        points[m] = pointsarray.getJSONObject(m).getInt("point");
                    }
                    System.out.println("array contains" + points.length + " elements");


                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else {
                Log.e("ServiceHandler", "Couldn't get any data from the url");
            }
            return null;
        }


protected void onPostExecute(ArrayList<HashMap<String, String>> result) {

            super.onPostExecute(result);
            pDialog.dismiss();




         for (int i = 0; i < points.length; i++) {
            tv = new TextView(getActivity());
            tv.setText(points[i]+",");
           tv.setTag(points[i]);
            yourLayout.addView(tv);
        }

        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int point = (int) view.getTag();
                Toast.makeText(getActivity(),point,Toast.LENGTH_SHORT).show();
            }
        });


        }
    }

3 个答案:

答案 0 :(得分:3)

积分array所以喜欢

tv.setText(""+points[i]);

答案 1 :(得分:2)

points[i]获取项目使用List并从points.get(i)获取项目使用public static Map<String, List<EnumKey>> crateEnumKeyMap() { Map<String, List<EnumKey>> map = new HashMap<>(); for (EnumKey enumKey : EnumKey.values()) { List<EnumKey> enumKeyList = map.get(enumKey.getGroupName()); if (enumKeyList == null) { enumKeyList = new ArrayList<>(); map.put(enumKey.groupName, enumKeyList); } enumKeyList.add(enumKey); } return map; } ;

答案 2 :(得分:2)

我看到你有两个问题。第一种是尝试使用int设置文本,第二种是尝试访问数组中的数据(您将其用作列表)。试试这样:

tv.setText(points[i] + "");