Reputation: 31
There are some questions about this but nothing seems to work. I am trying to get the content of a web page that is in the form of a Json Object.
Added this to proguard-rules.pro:
<pre><code>-keepattributes *Annotation*
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
@retrofit.http.* <methods>; }
-keepattributes Signature
-keep class com.google.gson.** { *; }
-keep class com.google.inject.** { *; }
-keep class org.apache.http.** { *; }
-keep class org.apache.james.mime4j.** { *; }
-keep class javax.inject.** { *; }
-keep class retrofit.** { *; } </pre></code>
My build.gradle:
<pre><code> apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
compileSdkVersion 23
buildToolsVersion "23.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.myApplication"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.0.0-alpha1'
compile 'com.android.support:design:24.0.0-alpha1'
compile 'com.android.support:support-v4:24.0.0-alpha1'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-appindexing:8.4.0'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.google.code.gson:gson:2.4'
compile 'org.glassfish:javax.annotation:10.0-b28'
}</pre></code>
Interface:
<pre><code> public interface LoginInterface {
@GET("?email=myEmail@gmailcom&password=opensesame")
Boolean getData(Callback<LoginJsonParser> cb);
}</pre></code>
LoginJsonParser class:
<pre><code> import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@Generated("org.jsonschema2pojo")
public class LoginJsonParser {
@SerializedName("success")
@Expose
private Integer success;
@SerializedName("message")
@Expose
private String message;
/**
*
* @return The success
*/
public Integer getSuccess() {
return success;
}
/**
*
* @param success The success
*/
public void setSuccess(Integer success) {
this.success = success;
}
/**
*
* @return The message
*/
public String getMessage() {
return message;
}
/**
*
* @param message The message
*/
public void setMessage(String message) {
this.message = message;
}
}</pre></code>
This is the error:
<pre><code>java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: retrofit.RetrofitError: LoginInterface.isLoginValid: HTTP method annotation is required (e.g., @GET, @POST, etc.).
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:400)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
at java.lang.reflect.Proxy.invoke(Proxy.java:393)
at $Proxy0.isLoginValid(Unknown Source)
at com.myApplication.activity.Login$UserLoginTask.doInBackground(Login.java:344)
at com.myApplication.activity.Login$UserLoginTask.doInBackground(Login.java:318)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.IllegalArgumentException: LoginInterface.isLoginValid: HTTP method annotation is required (e.g., @GET, @POST, etc.).
at retrofit.RestMethodInfo.methodError(RestMethodInfo.java:107)
at retrofit.RestMethodInfo.parseMethodAnnotations(RestMethodInfo.java:179)
at retrofit.RestMethodInfo.init(RestMethodInfo.java:117)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:294)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
at java.lang.reflect.Proxy.invoke(Proxy.java:393)
at $Proxy0.isLoginValid(Unknown Source)
at com.myApplication.activity.Login$UserLoginTask.doInBackground(Login.java:344)
at com.myApplication.activity.Login$UserLoginTask.doInBackground(Login.java:318)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818) </code></pre>
Upvotes: 1
Views: 1372
Reputation: 367
Using the wrong @GET
.
I was facing the same issue initially. A very common mistake when moving from Retrofit 1
to Retrofit 2
. In the interface, make sure that you are using the correct import statement for GET
.
I was unaware that I was using @GET
from retrofit.http and not @GET
from retrofit2.http
, changing the annotation from retrofit.http
to retrofit2.http
will do the job.
Upvotes: 1