Issue
I send my Data to my cloud server... which works fine. but i want to send all data which is present in SQlite db Table. i use Do while loop under Map method but it only send only one line. not whole.
String url = "http://blhc.com:1980/Mob/SendDoc.aspx";
SendDoctors(Context paramContext)
{
this.cont = paramContext;
}
@Override
protected String doInBackground(Void... voids) {
//region Sending
try{
ds = new DataSource(cont);
ds.open();
final Cursor cursor = ds.send();
if(cursor.moveToFirst())
do {
//region Sending Data
StringRequest stringRequest = new StringRequest(Request.Method.POST,url,
new Response.Listener<String>(){
@Override
public void onResponse(String response) {
Toast.makeText(cont,"Uploaded.." ,Toast.LENGTH_SHORT).show();
Log.v("jarvis" ,"Resposce" + response);
}
}
, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(cont,"Error.." ,Toast.LENGTH_SHORT).show();
error.printStackTrace();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> param = new HashMap<String, String>();
param.put("CELL_NO", cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_PHONE_NUM)));
param.put("M_DATE", M_DATE);
param.put("M_TIME", M_TIME);
param.put("EMP_ID", cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_EMP_ID)));
param.put("DOC_ID", cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_DOC_ID)));
param.put("SA", cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_SA)));
param.put("NOTE", "NOTE");
param.put("CO_ID", cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_CO_ID)));
param.put("LAT", cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_LOC_LAT)));
param.put("LNG", cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_LOC_LON)));
param.put("USER_ID", String.valueOf(LoginActivity.ID));
return param;
}
};
MySingleton.getmInstance(cont).addToRequestQue(stringRequest);
//endregion
}while (cursor.moveToNext());
}catch(Exception e){}
//endregion
return null;
}
ERROR
E/Volley: [191] NetworkDispatcher.run: Unhandled exception android.database.CursorIndexOutOfBoundsException: Index 6 requested, with a size of 6
android.database.CursorIndexOutOfBoundsException: Index 6 requested, with a size of 6
at android.database.AbstractCursor.checkPosition(AbstractCursor.java:460)
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
at com.example.zed.androidapplication.SendDoctors$3.getParams(SendDoctors.java:84)
at com.android.volley.Request.getBody(Request.java:468)
at com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:253)
at com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:227)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:107)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:97)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114)
W/System.err: com.android.volley.VolleyError: android.database.CursorIndexOutOfBoundsException: Index 6 requested, with a size of 6
W/System.err: at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:143)
W/System.err: Caused by: android.database.CursorIndexOutOfBoundsException: Index 6 requested, with a size of 6
W/System.err: at android.database.AbstractCursor.checkPosition(AbstractCursor.java:460)
W/System.err: at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
W/System.err: at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
W/System.err: at com.example.zed.androidapplication.SendDoctors$3.getParams(SendDoctors.java:84)
W/System.err: at com.android.volley.Request.getBody(Request.java:468)
W/System.err: at com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:253)
W/System.err: at com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:227)
W/System.err: at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:107)
W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:97)
W/System.err: at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114)
apply the Loop. But it Shows me some error...That I exceeded the limit.
one thing i have to clear thar On my web Server An Api take Variables not the array.. Now I thoink i clear my point?
Note: I am using volley lib to send data to server.
Thanks In advance. Really appreciate you help.
Solution
I resolve my Problem. Thanks all Of you. I post my answer of my Above code. and it works fine.
//region Sending
try{
ds = new DataSource(cont);
ds.open();
final Cursor cursor = ds.send();
if(cursor.moveToFirst())
do {
//region Sending Variables
final String CELL_NO = cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_PHONE_NUM));
final String M_DATE = cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_DATE));
final String M_TIME =cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_TIME));
final String EMP_ID = cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_EMP_ID));
final String UserID = String.valueOf(LoginActivity.ID) ;
final String DOC_ID = cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_DOC_ID));
final String SA= cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_SA));
final String NOTE = " - ";
final String CO_ID = cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_CO_ID));
final String LAT =cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_LOC_LAT));
final String LNG=cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_LOC_LON));
//endregion
//region Sending Data
Log.v("jarvis","Line = 1");
StringRequest stringRequest = new StringRequest(Request.Method.POST,url,
new Response.Listener<String>(){
@Override
public void onResponse(String response) {
ds.updateStatus(DOC_ID,M_DATE,M_TIME,EMP_ID); //true
Toast.makeText(cont,"Uploaded And Saved.." ,Toast.LENGTH_SHORT).show();
Log.v("jarvis","Line = 2");
}
}
, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.v("jarvis","Line = 3");
ds.updateFalse(DOC_ID,M_DATE,M_TIME,EMP_ID); //true
Toast.makeText(cont,"Error.." ,Toast.LENGTH_SHORT).show();
error.printStackTrace();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Log.v("jarvis","Line = 4");
Map<String, String> param = new HashMap<String, String>();
param.put("CELL_NO", CELL_NO);
param.put("M_DATE", M_DATE);
param.put("M_TIME", M_TIME);
param.put("EMP_ID", EMP_ID);
param.put("DOC_ID", DOC_ID);
param.put("SA", SA);
param.put("NOTE", NOTE);
param.put("CO_ID", CO_ID );
param.put("LAT", LAT);
param.put("LNG",LNG);
param.put("USER_ID",UserID);
return param;
}
};
Log.v("jarvis","Line = 5");
MySingleton.getmInstance(cont).addToRequestQue(stringRequest);
//endregion
Log.v("jarvis","Line = 6");
}while (cursor.moveToNext());
}catch(Exception e){}
//endregion
Answered By - Muhammad Zeeshan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.