"无法解析符号"错误 - Android Studio中的RetrofitError

时间:2015-11-14 19:47:21

标签: java android retrofit

我收到此错误但不确定原因。我会尝试提供信息,但如果您需要其他帮助,请告诉我。

代码:

package com.brasiltradefx.btfxalerts;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.io.IOException;
import java.util.List;

import retrofit.Call;
import retrofit.Callback;
import retrofit.Response;
import retrofit.Retrofit;


//Class having OnItemClickListener to handle the clicks on list
public class MainAlertsActivity extends AppCompatActivity implements ListView.OnItemClickListener {

    //Root URL of our web service
    public static final String ROOT_URL = "http://contrariantradefx.info/";

    //Strings to bind with intent will be used to send data to other activity
    public static final String KEY_ALERT_ID = "key_alert_id";
    public static final String KEY_ALERT_Order = "key_alert_order";
    public static final String KEY_ALERT_Pair = "key_alert_pair";
    public static final String KEY_ALERT_Rate = "key_alert_rate";
    public static final String KEY_ALERT_Target = "key_alert_target";
    public static final String KEY_ALERT_Date = "key_alert_date";

    //List view to show data
    private ListView listView;

    //List of type books this list will store type Book which is our data model
    private List<Alerts_book> alerts;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_alerts);

        //Initializing the listview
        listView = (ListView) findViewById(R.id.listViewAlerts);
        //Calling the method that will fetch data
        getAlerts();

        //Setting onItemClickListener to listview
        listView.setOnItemClickListener(this);
    }

    private void getAlerts(){
        //While the app fetched data we are displaying a progress dialog
        final ProgressDialog loading = ProgressDialog.show(this, "Fetching Data", "Please wait...", false, false);

        //Creating a rest adapter
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://api.github.com")
                .build();



        //Creating an object of our api interface
        GitHubService service = retrofit.create(GitHubService.class);

        //Defining the method

        GitHubService (new Call<List<Alerts_book>>() {


            @Override
            public Response<List<Alerts_book>> execute() throws IOException {
                return null;
            }

            @Override
            public void enqueue(Callback<List<Alerts_book>> callback) {

            }

            @Override
            public void cancel() {

            }

            @Override
            public Call<List<Alerts_book>> clone() {
                return null;
            }

            public void success(List<Alerts_book> list, Response response) {
                //Dismissing the loading progressbar
                loading.dismiss();

                //Storing the data in our list
                alerts = list;

                //Calling a method to show the list
                showList();
            }



            @Override
            public void failure(RetrofitError error) {
                //you can handle the errors here
            }
        });
    }

Gradle说:

:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources UP-TO-DATE
:app:mergeDebugAndroidTestResources UP-TO-DATE
:app:processDebugAndroidTestResources UP-TO-DATE
:app:generateDebugAndroidTestSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJavaWithJavac
C:\Users\Deryk\AndroidStudioProjects\BTFXAlerts2\app\src\main\java\com\brasiltradefx\btfxalerts\MainAlertsActivity.java:108: error: cannot find symbol
            public void failure(RetrofitError error) {
                                ^
  symbol: class RetrofitError
C:\Users\Deryk\AndroidStudioProjects\BTFXAlerts2\app\src\main\java\com\brasiltradefx\btfxalerts\MainAlertsActivity.java:107: error: method does not override or implement a method from a supertype
            @Override
            ^
C:\Users\Deryk\AndroidStudioProjects\BTFXAlerts2\app\src\main\java\com\brasiltradefx\btfxalerts\MainAlertsActivity.java:71: error: cannot find symbol
        GitHubService (new Call<List<Alerts_book>>() {
        ^
  symbol:   method GitHubService(<anonymous Call<List<Alerts_book>>>)
  location: class MainAlertsActivity
3 errors

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
  • 尝试: 使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获得更多日志输出。

建立失败

总时间:13.054秒

Gradle build:

Error:(71, 9) error: cannot find symbol method GitHubService(<anonymous Call<List<Alerts_book>>>)
Error:(107, 13) error: method does not override or implement a method from a supertype
Error:(108, 33) error: cannot find symbol class RetrofitError
C:\Users\Deryk\AndroidStudioProjects\BTFXAlerts2\app\src\main\java\com\brasiltradefx\btfxalerts\MainAlertsActivity.java

1 个答案:

答案 0 :(得分:0)

确定方法名称是。

@Override
public void onFailure(RetrofitError error) {
}

日志显示函数定义错误。这就是为什么它无法从超类型覆盖该方法并且在编译时失败。