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

how does service registration work with NsdManager?
Get values from the Datasnapshot object with keys in Firebase Android
How do I enter a name parameter while signing up a user in Firebase for Android
Login to twitter always goes to callback failure method
Why onDraw() is not called if Custom View extends ViewGroup?
Can't see the newest taken picture in the gallery?
#120 - Invalid album ID while uploading an image to Facebook group
strange broken simbol rendered in mobile chrome
Android consumable in app purchase flow called twice launchPurchaseFlow()
Mobile network 3g/4g randomly disconnects from the server
Binding several views to a Listener with multiple methods in Butterknife
Different display interface on the same devices
Encountered unregistered class ID: 12 SnappyDB
React native listview does not show all the rows
No view found error for a fragment with a ListView with a custom Adapter
android app crash since fab change

Categories

HOME
phpword
linkedin
ng-idle
amp-html
ns-3
youtube-data-api-v3
jsf-2.2
aws-cli
telegram-bot
visual-studio-emulator
gembox-spreadsheet
jtextpane
qpython
owin
plist
capistrano3
boost-icl
ember-cli
progress-bar
genexus-sd
handler
sinch
ntp
autodesk-designautomation
event-flow
anki
complex-numbers
dumpbin
angularjs-material
dynamic-jasper
getpixel
slacktextviewcontroller
protege4
sharepoint-workflow
lint
timing
kill
datacachefactory
rfc3339
ntvs
pair-programming
context-switch
custom-font
wpas
objectscript
structuremap4
cvxpy
mapxtreme
qtplugin
model-associations
i386
observablecollection
lz77
nullable
oracle-spatial
jdi
intel-c++
pax-exam
jdk1.7
typemock
jsvc
zxspectrum
broadband
nodelist
cosine-similarity
uncaught-typeerror
machine-instruction
lambda-architecture
alternate
jquery-slider
ios8-extension
file-not-found
extjs2
decoupling
websphere-esb
android-audiorecord
http-patch
jammer
cffile
onload-event
virtual-pc
curb
cakephp-1.2
u2netdk
google-ajax-api
exponentiation
cgbitmapcontextcreate
msr
mtu
silent
django-piston
entitykey
commercial-application

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