android - 无法调用没有参数的公共 android.app.Service()
问题描述
当我尝试从 API 改造响应中获取数据时,仅当服务 数组有数据时,如果它的空响应是成功的并且有其他所有数据,但是当 服务 数组对失败方法进行数据改造时,会给出以下消息:Failed to invoke public android.app.Service() with no args
第一次进行改造,卡在这里,累了,请提前致谢
当服务数组在 JSON 中有数据时出现错误
{
id: 1,
profile_image: "post_images/1594969413profile.jpg",
firstname: "bilawal",
lastname: "jabbar",
address: "Sansfrasico",
blog: [
{
id: 1,
artist_profile_id: 1,
title: "dsd",
description: "sdsd",
photo: "http://ec2-54-161-107-128.compute-1.server.com/post_images/1594811497blog.jpg",
likes: 0,
created_at: "15/07/20",
like_link: "http://ec2-54-161-107-128.compute-1.server.com/api/like_blog/2",
artist_image: "http://ec2-54-161-10128.compute1.server.com/post_images/1594969413profile.jpg",
single_blog_link: "http://ec2-54-161-107-128.compute-1.server.com/api/blog/2"
}],
services: [
{
name: "test",
details: "asasasasas",
feature_image: "http://ec2-54-161-107-128.comp1.server.com/post_images/1594987588feature.jpg",
price: 2,
price_type: "Iix",
rating: "No Yet Rating"
}]
}
当服务数组没有 JSON 中的数据时工作顺利无错误
{
id: 2,
profile_image: "no",
firstname: "Hamza",
lastname: "Dj Yo",
address: "no",
blog: [ ],
services: [ ]
}
服务等级
package com.example.djikon;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Service {
@SerializedName("name")
@Expose
private String name;
@SerializedName("details")
@Expose
private String details;
@SerializedName("feature_image")
@Expose
private String featureImage;
@SerializedName("price")
@Expose
private Integer price;
@SerializedName("price_type")
@Expose
private String priceType;
@SerializedName("rating")
@Expose
private String rating;
/**
* No args constructor for use in serialization
*
*/
public Service() {
}
public Service(String name, String details, String featureImage, Integer price, String priceType, String rating) {
super();
this.name = name;
this.details = details;
this.featureImage = featureImage;
this.price = price;
this.priceType = priceType;
this.rating = rating;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public String getFeatureImage() {
return featureImage;
}
public void setFeatureImage(String featureImage) {
this.featureImage = featureImage;
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
public String getPriceType() {
return priceType;
}
public void setPriceType(String priceType) {
this.priceType = priceType;
}
public String getRating() {
return rating;
}
public void setRating(String rating) {
this.rating = rating;
}
}
如果需要,还有主要对象类
package com.example.djikon;
import android.app.Service;
import java.util.List;
public class DJProfileModel {
private Integer id;
private String profile_image;
private String firstname;
private String lastname;
private String address;
private List<Blog_Model> blog;
private List<Service> services;
/**
* No args constructor for use in serialization
*
* @param body
*/
public DJProfileModel(DJProfileModel body) {
}
public DJProfileModel(Integer id, String profileImage, String firstname, String lastname, String address, List<Blog_Model> blog, List<Service> services) {
super();
this.id = id;
this.profile_image = profileImage;
this.firstname = firstname;
this.lastname = lastname;
this.address = address;
this.blog = blog;
this.services = services;
}
public Integer getId() {
return id;
}
public String getProfile_image() {
return profile_image;
}
public String getFirstname() {
return firstname;
}
public String getLastname() {
return lastname;
}
public String getAddress() {
return address;
}
public List<Blog_Model> getBlog() {
return blog;
}
public List<Service> getServices() {
return services;
}
}
解决方案
我在使用“Here” JSONCONVERT自动生成类时遇到了这个问题。为了解决这个问题,我为此服务响应数组创建了自己的类。现在它工作顺利。
这是我的手工课:
package com.example.djikon;
public class model {
private String name,
details,
feature_image,
price_type,
rating;
private int price;
public model(String name, String details, String feature_image, int price, String price_type, String rating) {
this.name = name;
this.details = details;
this.feature_image = feature_image;
this.price = price;
this.price_type = price_type;
this.rating = rating;
}
public String getName() {
return name;
}
public String getDetails() {
return details;
}
public String getFeature_image() {
return feature_image;
}
public int getPrice() {
return price;
}
public String getPrice_type() {
return price_type;
}
public String getRating() {
return rating;
}
}
推荐阅读
- angular - 角度反应形式 - 以编程方式将输入元素绑定到反应形式
- react-native - onPanResponderRelease 后,自动动画移动无法正常工作
- apache - Apache 无法启动。设置虚拟主机。MAMP
- android - 如何使用 listview 获取从 getItemAtPosition 中选择的 id
- matlab - Best approach to speed up pixel processing in matlab
- python - Is there a way of addressing all the inputs in a program?
- android - Continually Running Background Service
- bash - Fill empty fields - awk
- android - Load a single field of the object in realm
- angular - Firefox 控制台中的异常跟踪不使用源映射