无法解析方法 get(int)
can not resolve method get(int)
从服务器获得响应后,我将点存储在我的整数数组中,我试图将该数组添加到我的水平滚动视图中,但它在我的循环中给我错误,以下是我的代码,有人能帮忙吗?谢谢提前
这条线附近有错误
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
获取项目使用 points[i]
并从 List
获取项目使用 points.get(i)
;
分是一个array
所以喜欢
tv.setText(""+points[i]);
据我所知,您有 2 个问题。第一个是您尝试使用 int 设置文本,第二个是您尝试访问数组中数据的方式(您像使用列表一样使用它)。像这样尝试:
tv.setText(points[i] + "");
从服务器获得响应后,我将点存储在我的整数数组中,我试图将该数组添加到我的水平滚动视图中,但它在我的循环中给我错误,以下是我的代码,有人能帮忙吗?谢谢提前
这条线附近有错误
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
获取项目使用 points[i]
并从 List
获取项目使用 points.get(i)
;
分是一个array
所以喜欢
tv.setText(""+points[i]);
据我所知,您有 2 个问题。第一个是您尝试使用 int 设置文本,第二个是您尝试访问数组中数据的方式(您像使用列表一样使用它)。像这样尝试:
tv.setText(points[i] + "");