android


Retrofit Can't return Data


i'm probebly doing something wrong,
i'm trying to figure out how to use retrofit, so for now i'm calling back just a general ResponseBody, and not yet parsing anything, (just a simple http get)
but retrofit can't get the data, what am i doing wrong ? >
my Retrofit API >
public interface retrofitApi {
String baseUrl = "http://localhost:3003/";
#GET("api/radBox/getDegrees")
Call<ResponseBody> getCallData();
class Factory {
private static retrofitApi service;
public static retrofitApi getInstance() {
if (service == null) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build();
service = retrofit.create(retrofitApi.class);
return service;
} else {
return service;
}
}
}
}
and in my main Activity i put >
retrofitApi.Factory.getInstance().getCallData().enqueue(new Callback<ResponseBody>() {
#Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Log.d("myLogs", "log: " + response);
}
#Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.d("myLogs", "failed to Retrive Data");
}
});
I think your problem is caused by using "localhost". Looks like you are using your phone to connect to phone's 3003 port. Exchange the localhost to your Server IP to give a try.
I copy all your code in my retrofit project, I exchange the URL, everything is working well on my side, meaning your retrofit code has no problem.
Try use instead ResponseBody your model (for me it WeatherModel) which must will return from server.
Like this
String baseUrl = "http://api.openweathermap.org/";
#GET("data/2.5/weather")
Call<WeatherModel> getCallData(#Query("q") String q, #Query("lang") String lang,
#Query("appid") String appid);
and put in MainActivity like this
retrofitApi.Factory.getInstance()
.getCallData("Taganrog,ru", "ru", "bde41abf61e82b6209a544a5ea2ddb76")
.enqueue(new Callback<WeatherModel>() {
#Override
public void onResponse(Call<WeatherModel> call, Response<WeatherModel> response) {
Log.d("myLogs", "log: " + response);
}
#Override
public void onFailure(Call<WeatherModel> call, Throwable t) {
Log.d("myLogs", "log: " + "failed to Retrive Data");
}
});
It's works fine for me

Related Links

To open an Clicked Image in main activity to another activity
How to add gmail account in the android through app?
Layout display Issue using Android TabHost
How to keep a single activity instance but be able to update the view?
android:take in account xml values
Android Layout Structuring
Package Parsing Error
Using com.example.android.apis.graphics
What are extra feature cyanogen ROM provide in compare of Default Google provided ROM
How to add GPS signal strength bar in android?
Problem(Invalid File Response) in Image Upload in android
Moving multiple cars in a row for Android
Want to start programming on Android based platform. How to start it? [duplicate]
How to start and switch applications(APK) from a remote service?
In android How to track the other people using GPS?
Why three (redundant?) accelerometer variations in android sensors

Categories

HOME
notepad++
hyperlink
formal-languages
apiblueprint
knitr
grafana
bitbucket-api
soa
gembox-spreadsheet
regular-language
echo
angularfire2
odoo-8
okhttp
minecraft-forge
dkim
mautic
x-cart
php-5.6
endpoint
frequency-distribution
do-while
entitymanager
intershop
xmonad
sar
flask-sqlalchemy
moses
corpus
eviews
scatter3d
deltaspike
android-maps-extensions
activexobject
openwhisk
google-earth-engine
dm-script
node-mssql
metawidget
c9.io
microsoft-metro
plr
xmldocument
berkeley-db-je
clang++
puredata
flask-restful
ovf
yii2-api
tf
page-replacement
arq
ngmaterial
skin
arules
check-mk
libjpeg
type-theory
trigger.io
rsa-archer-grc
vcloud-director-rest-api
latin
mongodb-php
drawstring
expectations
eigenvector
database-relations
halcon
grass
exim4
highland.js
tfs-workitem
iokit
extjs-grid
botan
matlab-deployment
mraid
uvc
diff3
wcm
parallel-testing
grails-domain-class
lnk
ios8-extension
square-bracket
qscrollarea
kogrid
http-status-code-410
curb
panda3d
qtconcurrent
cakephp-1.2
subproject
objectquery
jdb
stress
jqote
timthumb
instantiationexception
easyb
jqueryform
scrollbars
linfu-dynamicproxy
firefox-3

Resources

Encrypt Message