retrofit response is true but no data fetch in serverDB










0














I have problem in parsing data thru my API. my retrofit code was sending true state on my response but if i look for my ServerDb, the response not come.



API:



 @POST("/api/Database/NewLocation")
Call<MapDetails> mapDetailLocation(@Body MapDetails
mapDetails);


Map Details:



 public class MapDetails 

private String serialNumber;
private String coordinate1;
private String coordinate2;
private String dateTime;
private String speed;
private Integer Port;

public String getSerialNumber()
return serialNumber;


public void setSerialNumber(String serialNumber)
this.serialNumber = serialNumber;


public String getCoordinate1()
return coordinate1;


public void setCoordinate1(String coordinate1)
this.coordinate1 = coordinate1;


public String getCoordinate2()
return coordinate2;


public void setCoordinate2(String coordinate2)
this.coordinate2 = coordinate2;


public String getDateTime()
return dateTime;


public void setDateTime(String dateTime)
this.dateTime = dateTime;


public String getSpeed()
return speed;


public void setSpeed(String speed)
this.speed = speed;


public Integer getPort()
return Port;


public void setPort(Integer port)
Port = port;


public MapDetails(String serialNumber, String coordinate1, String
coordinate2, String dateTime, String speed, Integer port)
this.serialNumber = serialNumber;
this.coordinate1 = coordinate1;
this.coordinate2 = coordinate2;
this.dateTime = dateTime;
this.speed = speed;
Port = port;






RetrofitClient:



 public class RetrofitClient 
private static final String BASE_URL="http://58.69.149.164:9114";
private static RetrofitClient mInstance;
private Retrofit retrofit;

private RetrofitClient()
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();

public static synchronized RetrofitClient getmInstance()
if(mInstance==null)
mInstance=new RetrofitClient();

return mInstance;

public Api getApi()
return retrofit.create(Api.class);


activity:

MapDetails mapDetails = new MapDetails(gg, lat, lon,
`enter code here`currentDateTimeString, "0", 9090);
setLocation(mapDetails);


DatabaseHelper databaseHelper = new
DatabaseHelper(getApplicationContext());
SQLiteDatabase db =
databaseHelper.getWritableDatabase();
boolean accepted =
databaseHelper.saveLocationToLocalDatabase(lat, lon,
currentDateTimeString, syncPassed, db);
if (accepted == true)
Snackbar.make(view, "Location Found", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
else
Snackbar.make(view, "Error Location", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();



private void setLocation(MapDetails mapDetails)

initializeRetrofit(mapDetails);


private void initializeRetrofit(MapDetails mapDetails)
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("http://58.69.149.164:9114")

.addConverterFactory(GsonConverterFactory.create());

Retrofit retrofit = builder.build();

Api locate = retrofit.create(Api.class);

SetMapLocationApiCaller(locate, mapDetails);




private void SetMapLocationApiCaller(Api locate, MapDetails
mapDetails)

Call<MapDetails> call =
locate.mapDetailLocation(mapDetails);
executeCallAsynchronously(call);


private void executeCallAsynchronously(Call call)
call.enqueue(new Callback()
@Override
public void onResponse(Call call, Response response)

Toast.makeText(NavDrawerFleet.this, ""+response,
Toast.LENGTH_LONG).show();


@Override
public void onFailure(Call call, Throwable t)
Toast.makeText(NavDrawerFleet.this,
t.getMessage(), Toast.LENGTH_SHORT).show();


);


The response here is true means the transaction is true.. but in my server db, no data fetched.....



also my api is this:



enter image description here



 if I send that, i will having a response from my serverDb...









share


Chnage your executeCallAsynchronously as



private void executeCallAsynchronously(Call call) 
call.enqueue(new Callback()
@Override
public void onResponse(Call call, Response response)

ServerResponse res = response.body();
int status = res.getStatus();
String msg = res.getMessage();


@Override
public void onFailure(Call call, Throwable t)
Toast.makeText(NavDrawerFleet.this,
t.getMessage(), Toast.LENGTH_SHORT).show();


);





share


TO



 Call<ServerResponse> call = 
locate.mapDetailLocation(mapDetails);
executeCallAsynchronously(call);
}


Chnage your executeCallAsynchronously as



private void executeCallAsynchronously(Call call) 
call.enqueue(new Callback()
@Override
public void onResponse(Call call, Response response)

ServerResponse res = response.body();
int status = res.getStatus();
String msg = res.getMessage();


@Override
public void onFailure(Call call, Throwable t)
Toast.makeText(NavDrawerFleet.this,
t.getMessage(), Toast.LENGTH_SHORT).show();


);





share


TO



 Call<ServerResponse> call = 
locate.mapDetailLocation(mapDetails);
executeCallAsynchronously(call);
}


Chnage your executeCallAsynchronously as



private void executeCallAsynchronously(Call call) {
call.enqueue(new Callback()
@Override
public void onResponse(Call call, Response response)

ServerResponse res = response.body();
int status = res.getStatus();
String msg = res.getMessage();


@Override
public void onFailure(Call call, Throwable t)
Toast.makeText(NavDrawerFleet.this,
t.getMessage(), Toast.LENGTH_SHORT).show();


);






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 '18 at 5:03

























answered Nov 12 '18 at 6:09









Ali AhmedAli Ahmed

1,2691314




1,2691314











  • upon the impplementation sir, is my code sending post to api.. is correct?
    – Julius Andaya
    Nov 12 '18 at 6:22










  • updated code according to your code, Try it. if you have any confusion let me know.
    – Ali Ahmed
    Nov 12 '18 at 6:42










  • ive got many errors
    – Julius Andaya
    Nov 12 '18 at 7:19










  • Where are you getting errors ?
    – Ali Ahmed
    Nov 12 '18 at 7:29










  • i toast the status and the msg..
    – Julius Andaya
    Nov 12 '18 at 7:34
















  • upon the impplementation sir, is my code sending post to api.. is correct?
    – Julius Andaya
    Nov 12 '18 at 6:22










  • updated code according to your code, Try it. if you have any confusion let me know.
    – Ali Ahmed
    Nov 12 '18 at 6:42










  • ive got many errors
    – Julius Andaya
    Nov 12 '18 at 7:19










  • Where are you getting errors ?
    – Ali Ahmed
    Nov 12 '18 at 7:29










  • i toast the status and the msg..
    – Julius Andaya
    Nov 12 '18 at 7:34















upon the impplementation sir, is my code sending post to api.. is correct?
– Julius Andaya
Nov 12 '18 at 6:22




upon the impplementation sir, is my code sending post to api.. is correct?
– Julius Andaya
Nov 12 '18 at 6:22












updated code according to your code, Try it. if you have any confusion let me know.
– Ali Ahmed
Nov 12 '18 at 6:42




updated code according to your code, Try it. if you have any confusion let me know.
– Ali Ahmed
Nov 12 '18 at 6:42












ive got many errors
– Julius Andaya
Nov 12 '18 at 7:19




ive got many errors
– Julius Andaya
Nov 12 '18 at 7:19












Where are you getting errors ?
– Ali Ahmed
Nov 12 '18 at 7:29




Where are you getting errors ?
– Ali Ahmed
Nov 12 '18 at 7:29












i toast the status and the msg..
– Julius Andaya
Nov 12 '18 at 7:34




i toast the status and the msg..
– Julius Andaya
Nov 12 '18 at 7:34

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256600%2fretrofit-response-is-true-but-no-data-fetch-in-serverdb%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo