在后台可运行线程内部改造arraylist response.body()错误

时间:2019-07-11 12:06:34

标签: java android mvvm retrofit2

最初,我在一个活动中进行了改造,所有调用都在主线程上完成。我试图通过具有View模型和存储库来切换到MVVM体系结构。我也试图运行改造调用后台线程。但是,当我尝试将Response.body()添加到Runnable方法内的列表中时,我从ArrayList中收到一条错误消息,指出“无法推断参数,无法解析构造函数”。

下面的代码示例:

API类:

var dictonary = new SqlCommand($"select Name, Value from Table where PId={id} and type<>{(int)Enum.PElement}", con);
                    SqlDataAdapter sda2 = new SqlDataAdapter(dictonary);
                    DataSet ds2 = new DataSet();
                    sda2.Fill(ds2);
                    IEnumerable<DataRow> dataRows = ds2.Tables[0].Rows.Cast<DataRow>().ToList();
                    var insData = new Dictionary<string, string>();

 foreach (DataRow row2 in dataRows )
 {
insData.ToDictionary(key => key.Name ?? t.TName, Val => Val.Value);
}

模型类:

  @GET("readMoodLineGraphToday.php")
Call <List<MoodLogLineGraphTestResponse>> getMoodLogsLineGraphToday(@Query("userId") int userId);

响应类别:

@SerializedName("moodBefore")
@Expose
private float moodBefore;

@SerializedName("posted")
@Expose
private String posted;

@SerializedName("day")
@Expose
private float day;

@SerializedName("cbtId")
@Expose
private int cbtID;


public MoodLogModel() {
}

public MoodLogModel(float moodBefore, String posted, float day, int cbtID) {
    this.moodBefore = moodBefore;
    this.posted = posted;
    this.day = day;
    this.cbtID = cbtID;
}

public float getMoodBefore() {
    return moodBefore;
}

public String getPosted() {
    return posted;
}

public float getDay() {
    return day;
}

public int getCbtID() {
    return cbtID;
}

ApiClient类:

@SerializedName("")
@Expose
private MoodLogModel data;

public MoodLogLineGraphTestResponse() {
}


public MoodLogLineGraphTestResponse(MoodLogModel data) {
    this.data = data;
}

public MoodLogModel getData() {
    return data;
}

此行:ArrayList列表= new ArrayList <>((((((MoodLogLineGraphTestResponse)response.body())。getData()));

在= new ArrayList之后在<>内部抛出错误

“无法推断参数,无法解析构造函数”

0 个答案:

没有答案