android


Post in retrofit [duplicate]


This question is an exact duplicate of:
NPE error using Retrofit
1 answer
I have an error when I try to use POST method through Retrofit 2 library. I want to ligon in vid.me service. This is the API of that service https://docs.vid.me/#api-Oauth-Authorize
but when I try to do this I have error:
FATAL EXCEPTION: main
java.lang.IllegalArgumentException: #Field parameters can only be used with form encoding. (parameter #1)
for method VideoApi.getUserLogin
at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:695)
at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:686)
at retrofit2.ServiceMethod$Builder.parameterError(ServiceMethod.java:704)
at retrofit2.ServiceMethod$Builder.parseParameterAnnotation(ServiceMethod.java:476)
at retrofit2.ServiceMethod$Builder.parseParameter(ServiceMethod.java:328)
at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:201)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:166)
at retrofit2.Retrofit$1.invoke(Retrofit.java:145)
at $Proxy1.getUserLogin(Native Method)
at com.example.vid_me_app.FeedFragment.Authorize(FeedFragment.java:48)
at com.example.vid_me_app.FeedFragment$1.onClick(FeedFragment.java:36)
at android.view.View.performClick(View.java:4231)
at android.view.View$PerformClick.run(View.java:17537)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:5751)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
at dalvik.system.NativeStart.main(Native Method)
my API class:
public interface VideoApi {
#GET("/videos/featured")
Call<Videos>getFeaturedVideo();
#GET("/videos/new")
Call<Videos>getNewVideo();
#POST("oauth/authorize")
Call<SignInResult> getUserLogin(#Field("username")String username,#Field("password")String password,Callback<SignInResults> callback);
}
my fragment:
public class FeedFragment extends Fragment {
EditText username;
EditText password;
Button btnLogin;
public static final String ROOT_URL = "https://api.vid.me/";
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_feed, container, false);
username = (EditText) rootView.findViewById(R.id.user_name_field);
password = (EditText) rootView.findViewById(R.id.password_field);
btnLogin = (Button)rootView.findViewById(R.id.button_login);
btnLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Authorize();
}
});
return rootView;
}
public void Authorize(){
Retrofit retrofitAdapter = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(ROOT_URL)
.build();
final VideoApi videoApi = retrofitAdapter.create(VideoApi.class);
// Call<SignInResults> call = videoApi.getUserLogin(username.getText().toString(),password.getText().toString(), new Callback<SignInResults>());
videoApi.getUserLogin(username.getText().toString(),password.getText().toString(), new Callback<SignInResults>() {
#Override
public void onResponse(Call<SignInResults> call, Response<SignInResults> response) {
Toast.makeText(getActivity(), response.body().getSignInResults().get(0).getCode(), Toast.LENGTH_SHORT).show();
}
#Override
public void onFailure(Call<SignInResults> call, Throwable t) {
}
});
}
}
Add #FormUrlEncoded annotation to the method:
#FormUrlEncoded
#POST("oauth/authorize")
Call<SignInResult> getUserLogin(#Field("username")String username,#Field("password")String password,Callback<SignInResults> callback);

Related Links

Mark all images in Grid View of Android
Android - Program still residing in memory even if the back button is pressed
What parts of an Android app should be fragments?
Why does my jQuery Mobile app not show correctly in the Android 4.0.3 browser?
Pros and Cons of saving image in SQLite
Starting an activity from a notification
Can't attach android app to device from itellij
How to send text from screen1 to screen2, using i.putExtra?
wrapping/overriding a ContentProvider
Android: How to display message when call is received and ended?
thread exiting with uncaught exception (group=0x4001b188)
Set multiple buttons in dialog
how to implement fragment in android
Parse Error while installing the apk file
ListView and SearchActivity for Android
User Operation is waiting for “Building Workspace”

Categories

HOME
url-redirection
embedded
gridview
cobalt
eslint
webdriver
rdbms
youtube-data-api-v3
sh
dojo
cq5
web-hosting
interpolation
tvos
vert.x
odoo-8
performancepoint
openstreetmap
fhir
heap
emoji
naivebayes
libc
selenium-ide
shared-libraries
plink
heat
capistrano3
glyphicons
google-picker
href
xunit
delimiter
inversion-of-control
jaws
winpe
boost-asio
volatile
cart
openwhisk
pop3
lint
cd
amazon-ses
mongoose-schema
tasm
install.packages
ssrs-2014
strftime
facebook-social-plugins
httr
servermanager
libgphoto2
automapper-5
singleinstance
payara-micro
reindex
check-mk
ziparchive
pacemaker
spring-cloud-feign
drawstring
delta
clipboard.js
embedding
createprocess
libav
httpruntime.cache
atan2
linklabel
rewrite
forwarding
rubaxa-sortable
ember-cli-rails
atoi
liquid-layout
alloy-ui
bufferedinputstream
user-permissions
phpldapadmin
gamekit
procedural-programming
variadic-templates
browserify-shim
winginx
fpdi
ecslidingviewcontroller
beaker-testing
kaleidoscope
mysql-error-2013
multiplexing
msr
instantiationexception
rowlex
nstokenfield
unmanagedresources

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App