Support Topics Documentation Slack YouTube Blog

Error Accessing created field

I added a DateTime field called “created” to my Master Table Class so as to access the corresponding “created” field from the backend
but i get this error when i try to access it

java.util.HashMap cannot be cast to ng.antigram.CloudDB.Master

//This is the Master class
package ng.antigram.CloudDB;

import com.anychart.scales.DateTime;
import com.backendless.persistence.Point;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Data
@Builder
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor

public class Master{

private String Status;
private String ProductId; //Globally Unique Identifier
private DateTime created;
private String AdvertTitle;
private String Wildcard;
private String Price;
private int PictureCount;
private int ViewCount;
private int CallCount;
private int ChatCount;
private String PosterId;
private String PosterPhone;
private String PosterWhatsApp;
private String State;
private String Region;

}

Hello @Nkekere_Tommy_Minimann

Try changing the type for the variable created from com.anychart.scales.DateTime to java.util.Date.
Please let me know if the error still occurs.

I’ve done that and the error still persists

try {

        Backendless.Data.of(Master.class).find(queryBuilder, new AsyncCallback<List<Master>>() {

            @Override
            public void handleResponse(List<Master> response) {

                try {


                    String advertTitle = response.get(position).getAdvertTitle();
                    holder.textViewAdvertTitle.setText(advertTitle);
                    Log.d(getClass().getName(), "AdvertTitle:" + advertTitle);

                    String posterId = response.get(position).getPosterId();
                    holder.textViewPosterId.setText(posterId);

                    DateTime date = response.get(position).getCreated();
                    DateFormat dateFormat = new SimpleDateFormat("E dd MMM yyyy  hh:mm:ss:aa");
                    holder.textViewDate.setText(dateFormat.format(date));


                                        }
                catch (IndexOutOfBoundsException e) {
                    e.printStackTrace();
                    Log.e(getClass().getName(), "Error Index:" + e.toString() + e.getLocalizedMessage());
                } catch (Exception e) {
                    e.printStackTrace();
                    Log.e(getClass().getName(), "Error->:" + e.getMessage());
                }

            }

            @Override
            public void handleFault(BackendlessFault fault) {

                Log.e(getClass().getName(), "Backendless Fault:" + fault.toString());

            }
        });
    } catch (IndexOutOfBoundsException e) {
        e.printStackTrace();
        Log.e(getClass().getName(), "Error Index:" + e.toString() + e.getLocalizedMessage());
    } catch (Exception e) {
        e.printStackTrace();
        Log.e(getClass().getName(), "Error->:" + e.getMessage());
    }

@Nkekere_Tommy_Minimann could you provide a full stack trace of error?

I’ve avoided the error by changing from class to Map but now I get another error: " Master Record Fault: Unable to adapt response to master"

I changed Private DateTime created // with small letter c
To Private DateTime Created // with capital letter C
And the error went away!
Thanks