2

日志猫:

原因 : java.lang.InstantiationException: Can't instantiate abstract class uk.ivanc.archimvp.model.entities.Campaigns

详细信息: Failed to invoke public uk.ivanc.archimvp.model.entities.Campaigns() with no args

Campaigns.java

@AutoValue
public abstract class Campaigns implements Parcelable{

    public abstract String remaining_days_formatted();

    public abstract String end_time_formatted();

    public abstract String badge_url();

    public abstract String newsletter_urlkey();

    public abstract String id_campaign();

    public abstract String navigation_url();

    public abstract Object promotion_line();

    public abstract ImmutableList<Videos> videos();

    public abstract String start_time_formatted();

    public abstract String subline();

    public abstract String banner_url();

    public abstract Object banner_url_original();

    public abstract String message_line_style();

    public abstract String end_time();

    public abstract String description();

    public abstract String name();

    public abstract Images images();

    public abstract String start_time();

    public abstract String url_key();

    public abstract String message_line();

    public abstract Object themeday();

    public static Builder builder() {
        return new AutoValue_Campaigns.Builder();
    }

    @AutoValue.Builder
    public abstract static class Builder {
        public abstract Builder remaining_days_formatted(String value);

        public abstract Builder end_time_formatted(String value);

        public abstract Builder badge_url(String value);

        public abstract Builder newsletter_urlkey(String value);

        public abstract Builder id_campaign(String value);

        public abstract Builder navigation_url(String value);

        public abstract Builder promotion_line(Object value);

        public abstract Builder videos(ImmutableList<Videos> value);

        public abstract Builder start_time_formatted(String value);

        public abstract Builder subline(String value);

        public abstract Builder banner_url(String value);

        public abstract Builder banner_url_original(Object value);

        public abstract Builder message_line_style(String value);

        public abstract Builder end_time(String value);

        public abstract Builder description(String value);

        public abstract Builder name(String value);

        public abstract Builder images(Images value);

        public abstract Builder start_time(String value);

        public abstract Builder url_key(String value);

        public abstract Builder message_line(String value);

        public abstract Builder themeday(Object value);

        public abstract Campaigns build();
    }

}

代码生成异常(onError被调用)

public void getCampaigns() {
        WestwingApplication application = WestwingApplication.get(campaignsMvpView.getContext());
        WestwingService westwingService = application.getWestwingService();
        subscription = westwingService.getCampaigns()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(application.defaultSubscribeScheduler())
                .subscribe(new Observer<List<Campaigns>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(List<Campaigns> campaigns) {
                        campaignsMvpView.showCampaigns(campaigns);
                    }
                });
    }
}

依赖项.gradle

dependencies = [
            appCompat: "com.android.support:appcompat-v7:$supportLibraryVersion",
            cardView: "com.android.support:cardview-v7:$supportLibraryVersion",
            recyclerView: "com.android.support:recyclerview-v7:$supportLibraryVersion",
            retrofit: "com.squareup.retrofit2:retrofit:$retrofitVersion",
            retrofitConverterGson: "com.squareup.retrofit2:converter-gson:$retrofitVersion",
            retrofitAdapterRxJava: "com.squareup.retrofit2:adapter-rxjava:$retrofitVersion",
            picasso: 'com.squareup.picasso:picasso:2.5.2',
            rxAndroid: 'io.reactivex:rxandroid:1.1.0',
            circleImageView: 'de.hdodenhof:circleimageview:1.3.0',
            jUnit: 'junit:junit:4.12',
            mockito: 'org.mockito:mockito-core:1.10.19',
            robolectric: 'org.robolectric:robolectric:3.0',
            autoparcel: 'frankiesardo:auto-parcel:1.0.1',
            aptautoparcel: 'frankiesardo:auto-parcel:1.0.1',
            palette: "com.android.support:palette-v7:$supportLibraryVersion",
            design: "com.android.support:design:$supportLibraryVersion"
    ]
4

1 回答 1

-1

将此方法添加到您的模型中

public static TypeAdapter<Campaigns> typeAdapter(Gson gson) { 
   return new AutoValue_Campaigns.GsonTypeAdapter(gson);}
于 2017-07-24T16:29:14.703 回答