I am working on android application. I want to get specific index of id , but it returns always first no of index id or application crashes .please help me how to solve error. Thanks
here is my code:
protected Void doInBackground(Void... arg0)
{
HttpService httpService = new HttpService("http://192.168.0.103/GetActiveGroupMember.php");
try
{
httpService.ExecutePostRequest();
if(httpService.getResponseCode() == 200)
{
result = httpService.getResponse();
ArrayList<Integer> m_idlist = null;
listid = new ArrayList<>();
listid.add(result);
// System.out.println("ListID... "+listid+" ListId Size "+listid.size());
System.out.println("ListID... "+listid+" ListId Size "+listid.size());
// Log.d("Result", result);
System.out.println("Result "+result);
if(result != null)
{
JSONArray jsonArray = null;
try {
jsonArray = new JSONArray(result);
JSONObject object;
JSONArray array;
member m;
members = new ArrayList<member>();
for(int i=0; i<jsonArray.length(); i++)
{
m= new member();
object = jsonArray.getJSONObject(i);
// m.username = object.getString("username");
m.id = object.getInt("id");
members.add(m);
int m_id = m.id;
System.out.println("mem_id = "+m_id);
m_idlist = new ArrayList<Integer>();
m_idlist.add(i);
System.out.println("five no id = "+m_idlist.get(i)); // TO print all Id
}
if(m_idlist.size()>5){
System.out.println("five no id = "+m_idlist.get(5));
}
// System.out.println("Total member = "+members.size());
}
Error:
W/System.err: java.lang.IndexOutOfBoundsException: Invalid index 5, size is 1
W/System.err: at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
W/System.err: at java.util.ArrayList.get(ArrayList.java:308)
W/System.err: at com.example.moraya.adminmodule.GetActiveGroupMemberACtivity$GetHttpResponse.doInBackground(GetActiveGroupMemberACtivity.java:121)
W/System.err: at com.example.moraya.adminmodule.GetActiveGroupMemberACtivity$GetHttpResponse.doInBackground(GetActiveGroupMemberACtivity.java:56)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err: at java.lang.Thread.run(Thread.java:841)
W/EGL_genymotion: eglSurfaceAttrib not implemented
Thank you so much.