Java 在共享首选项中存储自定义对象(具有字符串、日期、列表等字段)的arraylist

Java 在共享首选项中存储自定义对象(具有字符串、日期、列表等字段)的arraylist,java,android,arraylist,save,sharedpreferences,Java,Android,Arraylist,Save,Sharedpreferences,我试图在共享首选项中保存客户机的arraylist,但内存不足错误。我是新手,不知道怎么做?我查看了很多关于stackoverflow的页面,但找不到一个适合我的页面,也找不到一个包含ArrayList自定义对象的页面,其中每个对象都包含更多带有自定义对象的ArrayList 客户端对象: public class Client implements Serializable, Comparable<Client> { private int clientID; pr

我试图在共享首选项中保存客户机的arraylist,但内存不足错误。我是新手,不知道怎么做?我查看了很多关于stackoverflow的页面,但找不到一个适合我的页面,也找不到一个包含
ArrayList
自定义对象的页面,其中每个对象都包含更多带有自定义对象的ArrayList

客户端对象:

public class Client implements Serializable, Comparable<Client> {
    private int clientID;
    private String name;
    private String phone;
    private String email;
    private String url;
    private Double turnover;
    private String visitAddress;
    private String visitCity;
    private String visitZipcode;
    private String visitCountry;
    private String postalAddress;
    private String postalCity;
    private String postalZipcode;
    private String postalCountry;
    private Drawable clientImage;
    private List<Contact> contactList =  new ArrayList<Contact>();
    private List<Project> projectList = new ArrayList<Project>();
    private List<Task> taskList = new ArrayList<Task>();
    private List<Order> orderList = new ArrayList<Order>();


    public Client(int clientID, String Name, String Phone, String Email, String URL, Double Turnover,
                  String VisitAddress, String VisitCity, String VisitZipcode, String VisitCountry,
                  String PostalAddress, String PostalCity, String PostalZipcode, String PostalCountry,
                  List contactList, List projectList, List taskList, List orderList){
            super();
        this.clientID = clientID;
        this.name = Name;
            this.phone = Phone;
            this.email = Email;
            this.url = URL;
            this.turnover = Turnover;
            this.visitAddress = VisitAddress;
            this.visitCity = VisitCity;
            this.visitZipcode = VisitZipcode;
            this.visitCountry = VisitCountry;
            this.postalAddress = PostalAddress;
            this.postalCity = PostalCity;
            this.postalZipcode = PostalZipcode;
            this.postalCountry = PostalCountry;
            this.contactList = contactList;
            this.projectList = projectList;
            this.taskList = taskList;
            this.orderList = orderList;
    }


    public String getName() {
        return name;
    }

    public String getPhone() {
        return phone;
    }

    public String getEmail() {
        return email;
    }

    public String getUrl() {
        return url;
    }

    public Double getTurnover() {

        return turnover;
    }

    public String getVisitAddress() {
        return visitAddress;
    }

    public String getVisitCity() {
        return visitCity;
    }

    public String getVisitZipcode() {
        return visitZipcode;
    }

    public String getVisitCountry() {
        return visitCountry;
    }

    public String getPostalAddress() {
        return postalAddress;
    }

    public String getPostalCity() {
        return postalCity;
    }

    public String getPostalZipcode() {
        return postalZipcode;
    }

    public String getPostalCountry() {
        return postalCountry;
    }

    public List<Contact> getContactList(){
        return contactList;
    }

    public List<Project> getProjectList(){
        return projectList;
    }

    public List<Task> getTaskList(){
        return taskList;
    }

    public List<Order> getOrderList() {
        return orderList;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public void setTurnover(Double turnover) {
        this.turnover = turnover;
    }

    public void setVisitAddress(String visitAddress) {
        this.visitAddress = visitAddress;
    }

    public void setVisitCity(String visitCity) {
        this.visitCity = visitCity;
    }

    public void setVisitZipcode(String visitZipcode) {
        this.visitZipcode = visitZipcode;
    }

    public void setVisitCountry(String visitCountry) {
        this.visitCountry = visitCountry;
    }

    public void setPostalAddress(String postalAddress) {
        this.postalAddress = postalAddress;
    }

    public void setPostalCity(String postalCity) {
        this.postalCity = postalCity;
    }

    public void setPostalZipcode(String postalZipcode) {
        this.postalZipcode = postalZipcode;
    }

    public void setPostalCountry(String postalCountry) {
        this.postalCountry = postalCountry;
    }

    public Drawable getClientImage() {
        return clientImage;
    }

    public void setClientImage(Drawable clientImage) {
        this.clientImage = clientImage;
    }

    public int getClientID() {
        return clientID;
    }

    public void setClientID(int clientID) {
        this.clientID = clientID;
    }
public类客户端实现了可序列化、可比较的{
私人int客户ID;
私有字符串名称;
私人电话;
私人字符串电子邮件;
私有字符串url;
私人双营业额;
私服;
私有字符串访问性;
私有字符串visitZipcode;
私人字符串访问国家;
私服;
私有字符串后循环;
私有字符串postalZipcode;
私人字符串邮政国家;
私人可提取客户图像;
private List contactList=new ArrayList();
private List projectList=new ArrayList();
private List taskList=new ArrayList();
private List orderList=new ArrayList();
公共客户端(int clientID、字符串名称、字符串电话、字符串电子邮件、字符串URL、双营业额、,
字符串VisitAddress、字符串VisitCity、字符串VisitZipcode、字符串VisitCountry、,
字符串PostalAddress、字符串PostalCity、字符串PostalZipcode、字符串PostalCountry、,
列表联系人列表、列表项目列表、列表任务列表、列表订单列表){
超级();
this.clientID=clientID;
this.name=名称;
this.phone=电话;
this.email=电子邮件;
this.url=url;
这个。营业额=营业额;
this.visitAddress=visitAddress;
this.visitCity=visitCity;
this.visitZipcode=visitZipcode;
this.visitCountry=visitCountry;
this.postalAddress=postalAddress;
this.postalCity=postalCity;
this.postalZipcode=postalZipcode;
this.postalCountry=postalCountry;
this.contactList=联系人列表;
this.projectList=项目列表;
this.taskList=任务列表;
this.orderList=订单列表;
}
公共字符串getName(){
返回名称;
}
公共字符串getPhone(){
回电话;
}
公共字符串getEmail(){
回复邮件;
}
公共字符串getUrl(){
返回url;
}
公共双getTurnover(){
回报率;
}
公共字符串getVisitAddress(){
回访服装;
}
公共字符串getVisitCity(){
返回可视性;
}
公共字符串getVisitZipcode(){
返回visitZipcode;
}
公共字符串getVisitCountry(){
回国;
}
公共字符串getPostalAddress(){
退回邮资;
}
公共字符串getPostLCITY(){
返回后循环;
}
公共字符串getPostalZipcode(){
返回邮政编码;
}
公共字符串getPostalCountry(){
回国;
}
公共列表getContactList(){
返回联系人列表;
}
公共列表getProjectList(){
返回项目列表;
}
公共列表getTaskList(){
返回任务列表;
}
公共列表getOrderList(){
返回订单列表;
}
公共void集合名(字符串名){
this.name=名称;
}
公用无效设置电话(字符串电话){
this.phone=电话;
}
公用电子邮件(字符串电子邮件){
this.email=电子邮件;
}
公共void setUrl(字符串url){
this.url=url;
}
公众营业额(双倍营业额){
这个。营业额=营业额;
}
公共无效设置visitAddress(字符串visitAddress){
this.visitAddress=visitAddress;
}
public void setVisitCity(字符串visitCity){
this.visitCity=visitCity;
}
public void setVisitZipcode(字符串visitZipcode){
this.visitZipcode=visitZipcode;
}
public void setVisitCountry(字符串visitCountry){
this.visitCountry=visitCountry;
}
公共无效设置邮资(字符串邮资){
this.postalAddress=postalAddress;
}
public void setPostalCity(字符串postalCity){
this.postalCity=postalCity;
}
public void setPostalZipcode(字符串postalZipcode){
this.postalZipcode=postalZipcode;
}
public void setPostalCountry(字符串postalCountry){
this.postalCountry=postalCountry;
}
公共绘图getClientImage(){
返回客户端图像;
}
public void setClientImage(可提取的clientImage){
this.clientImage=clientImage;
}
public int getClientID(){
返回客户ID;
}
public void setClientID(int clientID){
this.clientID=clientID;
}
基础项目对象:(也包括自定义对象列表)

公共类项目实现了可序列化、可比较的{
私有字符串clientName;
私有字符串projectName;
私有字符串项目描述;
私有字符串状态;
私人Gregorianalendar项目日期;
private List projectTimeRegestrationList=新建ArrayList();
private List workOrderList=new ArrayList();
公共项目(String clientName、String projectName、String ProjectDescription、String projectStatus、GregorianCalendar projectDate、List projectTimeRegestrationList、List workOrderList){
this.projectName=projectName;
this.projectDescription=项目描述;
this.projectStatus=项目状态;
this.projectDate=项目日期;
this.clientName=clientName;
this.projectTimeRegestrationList=projectTimeRegestrationList;
this.workOrderList=workOrderList;
}
公共字符串
public class Project implements Serializable, Comparable<Project>{

    private String clientName;
    private String projectName;
    private String projectDiscription;
    private String  projectStatus;
    private GregorianCalendar projectDate;
    private List<TimeSheet> projectTimeRegestrationList = new ArrayList<>();
    private List<WorkOrder> workOrderList = new ArrayList<WorkOrder>();


    public Project(String clientName, String projectName, String projectDiscription, String projectStatus, GregorianCalendar projectDate, List projectTimeRegestrationList, List workOrderList) {
        this.projectName = projectName;
        this.projectDiscription = projectDiscription;
        this.projectStatus = projectStatus;
        this.projectDate = projectDate;
        this.clientName = clientName;
        this.projectTimeRegestrationList = projectTimeRegestrationList;
        this.workOrderList = workOrderList;
    }

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public String getProjectDiscription() {
        return projectDiscription;
    }

    public void setProjectDiscription(String projectDiscription) {
        this.projectDiscription = projectDiscription;
    }

    public String getProjectStatus() {
        return projectStatus;
    }

    public void setProjectStatus(String projectStatus) {
        this.projectStatus = projectStatus;
    }

    public GregorianCalendar getProjectDate() {
        return projectDate;
    }

    public void setProjectDate(GregorianCalendar projectDate) {
        this.projectDate = projectDate;
    }

    public String getClientName() {
        return clientName;
    }

    public void setClientName(String clientName) {
        this.clientName = clientName;
    }

    public List<TimeSheet> getProjectTimeRegestrationList() {
        return projectTimeRegestrationList;
    }

    public List<WorkOrder> getWorkOrderList() {
        return workOrderList;
    }
try {
                JSONArray jsonArray=new JSONArray();
                JSONObject object1=new JSONObject();
                object1.put("url","myurl");
                object1.put("phone","myphonenumber");
                object1.put("country","mycountry");
                jsonArray.put(object1);

                //adding another object
                JSONObject object2=new JSONObject();
                object2.put("url","anotherurl");
                object2.put("phone","anotherphonenumber");
                object2.put("country","anothercountry");
                jsonArray.put(object2);


            } catch (JSONException e) {
                e.printStackTrace();
            }
try {
                JSONArray jsonArray=new JSONArray();
                JSONObject object1=new JSONObject();
                object1.put("url","myurl");
                object1.put("phone","myphonenumber");
                object1.put("country","mycountry");

                //saving a list of another object contaning firstname and lastname
                JSONArray listArray=new JSONArray();

                //supposing your list contains 10 objects
                for(int f=0;f<10;f++){
                    JSONObject listobject=new JSONObject();
                    listobject.put("firstname","myfirstname");
                    listobject.put("lastname","mylastname");
                    listArray.put(listobject);
                }
                //now the list array we added as an object of the jsonArray variable
                JSONObject object2=new JSONObject(); //object2 containing the list of firstname and lastname
                object2.put("list",listArray.toString());
                jsonArray.put(object1);//object1 contains the url, phone, and country
                jsonArray.put(object2);//object2 contains the list of firstname and lastname


            } catch (JSONException e) {
                e.printStackTrace();
            }