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

这条线附近的错误

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();
            }
        });


        }
    }

最佳答案

是一个 array 所以喜欢

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

关于android - 无法解析方法 get(int),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33754600/

10-10 09:45