Cannot cast java.util.HashMap

Hello
Here’s my code

protected List<WeekViewEvent> doInBackground(Integer... integers){
            List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();
            try {
                Backendless.Data.mapTableToClass("Events",BackendlessCollection.class);
                String whereClause = "year = " + integers[0] + " AND month = " + integers[1];
                BackendlessDataQuery dataQuery = new BackendlessDataQuery();
                dataQuery.setWhereClause(whereClause);
                BackendlessCollection<Events> result = Backendless.Persistence.of(Events.class).find(dataQuery);
                // String[] items = new String[result.getCurrentPage().size()];


                for( int i = 0; i < result.getCurrentPage().size(); i++ ){
                    Events event_item = result.getCurrentPage().get(i);
                    //items[ i ] = String.valueOf( event.getTitle() );
                    //items[ i ] = Integer.valueOf( ((Events) result.getCurrentPage().get( i )).getHour_of_day() );


                    Calendar startTime = Calendar.getInstance();
                    startTime.set(Calendar.HOUR_OF_DAY, event_item.getHour_of_day());

when i debug
startTime.set(Calendar.HOUR_OF_DAY, event_item.getHour_of_day()) = Cannot cast java.util.HashMap

what i need to do?

Mapping BackendlessCollection class to a table is a very bad idea. It is the root of the problem you’re experiencing. Remove the following line and try again:

Backendless.Data.mapTableToClass("Events",BackendlessCollection.class);

Mark

i remove but nothing change. in attached file printscreen. can you check please

Are you using the latest Backendless SDK? How long ago did you download it?

I downloaded 3 weeks ago. An other code with Backendless data work fine

If you downloaded before June 10th, you would need to download again.

Could you post the source code of the Events class? and a screenshot of the Events table schema?

Mark

package com.backendless.atyraufitness.messaging;


import com.backendless.Backendless;
import com.backendless.BackendlessCollection;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.persistence.BackendlessDataQuery;






public class Events
{
  private Integer minute;
  private Integer month;
  private java.util.Date updated;
  private Integer hour_of_day;
  private Integer hour_end;
  private java.util.Date created;
  private String ownerId;
  private String objectId;
  private Integer minute_end;
  private Integer color;
  private Integer year;
  private Integer day_of_month;
  private String title;


  public Integer getMinute()
  {
    return minute;
  }


  public void setMinute( Integer minute )
  {
    this.minute = minute;
  }


  public Integer getMonth()
  {
    return month;
  }


  public void setMonth( Integer month )
  {
    this.month = month;
  }


  public java.util.Date getUpdated()
  {
    return updated;
  }


  public Integer getHour_of_day()
  {
    return hour_of_day;
  }


  public void setHour_of_day( Integer hour_of_day )
  {
    this.hour_of_day = hour_of_day;
  }


  public Integer getHour_end()
  {
    return hour_end;
  }


  public void setHour_end( Integer hour_end )
  {
    this.hour_end = hour_end;
  }


  public java.util.Date getCreated()
  {
    return created;
  }


  public String getOwnerId()
  {
    return ownerId;
  }


  public String getObjectId()
  {
    return objectId;
  }


  public Integer getMinute_end()
  {
    return minute_end;
  }


  public void setMinute_end( Integer minute_end )
  {
    this.minute_end = minute_end;
  }


  public Integer getColor()
  {
    return color;
  }


  public void setColor( Integer color )
  {
    this.color = color;
  }


  public Integer getYear()
  {
    return year;
  }


  public void setYear( Integer year )
  {
    this.year = year;
  }


  public Integer getDay_of_month()
  {
    return day_of_month;
  }


  public void setDay_of_month( Integer day_of_month )
  {
    this.day_of_month = day_of_month;
  }


  public String getTitle()
  {
    return title;
  }


  public void setTitle( String title )
  {
    this.title = title;
  }




  public Events save()
  {
    return Backendless.Data.of( Events.class ).save( this );
  }


  public Future&lt;Events&gt; saveAsync()
  {
    if( Backendless.isAndroid() )
    {
      throw new UnsupportedOperationException( "Using this method is restricted in Android" );
    }
    else
    {
      Future&lt;Events&gt; future = new Future&lt;Events&gt;();
      Backendless.Data.of( Events.class ).save( this, future );


      return future;
    }
  }


  public void saveAsync( AsyncCallback&lt;Events&gt; callback )
  {
    Backendless.Data.of( Events.class ).save( this, callback );
  }


  public Long remove()
  {
    return Backendless.Data.of( Events.class ).remove( this );
  }


  public Future&lt;Long&gt; removeAsync()
  {
    if( Backendless.isAndroid() )
    {
      throw new UnsupportedOperationException( "Using this method is restricted in Android" );
    }
    else
    {
      Future&lt;Long&gt; future = new Future&lt;Long&gt;();
      Backendless.Data.of( Events.class ).remove( this, future );


      return future;
    }
  }


  public void removeAsync( AsyncCallback&lt;Long&gt; callback )
  {
    Backendless.Data.of( Events.class ).remove( this, callback );
  }


  public static Events findById( String id )
  {
    return Backendless.Data.of( Events.class ).findById( id );
  }


  public static Future&lt;Events&gt; findByIdAsync( String id )
  {
    if( Backendless.isAndroid() )
    {
      throw new UnsupportedOperationException( "Using this method is restricted in Android" );
    }
    else
    {
      Future&lt;Events&gt; future = new Future&lt;Events&gt;();
      Backendless.Data.of( Events.class ).findById( id, future );


      return future;
    }
  }


  public static void findByIdAsync( String id, AsyncCallback&lt;Events&gt; callback )
  {
    Backendless.Data.of( Events.class ).findById( id, callback );
  }


  public static Events findFirst()
  {
    return Backendless.Data.of( Events.class ).findFirst();
  }


  public static Future&lt;Events&gt; findFirstAsync()
  {
    if( Backendless.isAndroid() )
    {
      throw new UnsupportedOperationException( "Using this method is restricted in Android" );
    }
    else
    {
      Future&lt;Events&gt; future = new Future&lt;Events&gt;();
      Backendless.Data.of( Events.class ).findFirst( future );


      return future;
    }
  }


  public static void findFirstAsync( AsyncCallback&lt;Events&gt; callback )
  {
    Backendless.Data.of( Events.class ).findFirst( callback );
  }


  public static Events findLast()
  {
    return Backendless.Data.of( Events.class ).findLast();
  }


  public static Future&lt;Events&gt; findLastAsync()
  {
    if( Backendless.isAndroid() )
    {
      throw new UnsupportedOperationException( "Using this method is restricted in Android" );
    }
    else
    {
      Future&lt;Events&gt; future = new Future&lt;Events&gt;();
      Backendless.Data.of( Events.class ).findLast( future );


      return future;
    }
  }


  public static void findLastAsync( AsyncCallback&lt;Events&gt; callback )
  {
    Backendless.Data.of( Events.class ).findLast( callback );
  }


  public static BackendlessCollection&lt;Events&gt; find( BackendlessDataQuery query )
  {
    return Backendless.Data.of( Events.class ).find( query );
  }


  public static Future&lt;BackendlessCollection&lt;Events&gt;> findAsync( BackendlessDataQuery query )
  {
    if( Backendless.isAndroid() )
    {
      throw new UnsupportedOperationException( "Using this method is restricted in Android" );
    }
    else
    {
      Future&lt;BackendlessCollection&lt;Events&gt;> future = new Future&lt;BackendlessCollection&lt;Events&gt;>();
      Backendless.Data.of( Events.class ).find( query, future );


      return future;
    }
  }


  public static void findAsync( BackendlessDataQuery query, AsyncCallback&lt;BackendlessCollection&lt;Events&gt;> callback )
  {
    Backendless.Data.of( Events.class ).find( query, callback );
  }
}

I need a screenshot of the schema, not the data. You can get the schema if you click the big red button in the upper-right corner of the data screen (make sure the Events table is selected when you do that).

Mark

Also, please send me an email with your app id and Android secret key - I’d like to run the same test myself.

Regards,
Mark

shema

Just a reminder to send me your app id and android secret ket so I can replicate the problem. My email is mark@backendless.com.

Mark

another class work fine

Снимок.JPG

Do you have both Events and Event classes? The code you showed earlier referenced Events (plural case), then the latest screenshot references the Event class (singular case).

The name of the class must match the name of the table.

Mark

No, i just rename events to event

Did you rename the table too?

yes of cource

I tried it locally with my app and it works fine. I need to have access to your app to see the problem. If you’d like us to diagnose it further, please share your app-id and secret key.

Regards,
Mark

what email address i can send app?

mark@backendless.com

I sended