User data was put into a table in Backendless. How to retrieve that user’s data?
I have been reading Backendless documentation and trying example code and not succeeding.
One example looked promissing, but it had a compile time error for </Map>, so I commented it out.
Then it had a runtime error.
Even if the code did run, I don’t know how to get user data from ‘contactObjects.’
package com.examples.contact;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.backendless.Backendless;
import com.backendless.IDataStore;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.exceptions.BackendlessFault;
import com.backendless.persistence.DataQueryBuilder;
import java.util.List;
import java.util.Map;
public class FindContactActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.find_contact);
Backendless.setUrl( Defaults.SERVER_URL );
Backendless.initApp( getApplicationContext(), Defaults.APPLICATION_ID, Defaults.API_KEY );
}
void onFindContact() { // in find_contact.xml, find_button, android:onClick="onFindContact"
IDataStore<Map> contactStorage = Backendless.Data.of( "Contact" );
DataQueryBuilder queryBuilder = DataQueryBuilder.create();
// set where clause
queryBuilder.setWhereClause( "age < 30" );
// set related columns
queryBuilder.setRelated( "address", "preferences" );
// request sorting
queryBuilder.setSortBy( "name" );
//set offset and page size
queryBuilder.setPageSize( 20 );
queryBuilder.setOffset( 40 );
contactStorage.find( queryBuilder, new AsyncCallback<List<Map>>()
{
@Override
public void handleResponse( List<Map> contactObjects )
{
Log.i( "MYAPP", "Retrieved " + contactObjects.size() + " objects" );
Toast.makeText(FindContactActivity.this,"Retrieved " + contactObjects.size() + " objects from Backendless table", Toast.LENGTH_LONG).show();
}
@Override
public void handleFault( BackendlessFault fault )
{
//Log.e( "MYAPP", "Server reported an error " + fault.getMessage );//compile error at 'getMessage'
Toast.makeText(FindContactActivity.this,"Backendless Server reported an error ", Toast.LENGTH_LONG).show();
}
} );
//</Map> //compile error at '</map>'
}
}
Could you please copy/paste the error in its entirety?
[ 05-03 16:16:21.941 3604: 3604 E/ ]
Device driver API match
Device driver API version: 20
User space API version: 20
[ 05-03 16:16:21.941 3604: 3604 E/ ]
mali: REVISION=Linux-r3p2-01rel2 BUILD_DATE=Mon Nov 18 21:41:36 KST 2013
05-03 16:16:21.956 3604-3604/com.examples.contact D/OpenGLRenderer: Enabling debug mode 0
05-03 16:16:27.586 3604-3605/com.examples.contact D/dalvikvm: GC_CONCURRENT freed 199K, 14% free 9257K/10648K, paused 3ms+2ms, total 21ms
05-03 16:16:27.671 3604-3604/com.examples.contact E/MoreInfoHPW_ViewGroup: Parent view is not a TextView
05-03 16:16:39.971 3604-3604/com.examples.contact I/dalvikvm: Could not find method java.util.Objects.requireNonNull, referenced from method com.backendless.persistence.MapDrivenDataStore.getObjectCount
05-03 16:16:39.971 3604-3604/com.examples.contact W/dalvikvm: VFY: unable to resolve static method 20982: Ljava/util/Objects;.requireNonNull (Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;
05-03 16:16:39.971 3604-3604/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x71 at 0x0006
05-03 16:16:39.971 3604-3604/com.examples.contact I/dalvikvm: Could not find method java.util.Objects.requireNonNull, referenced from method com.backendless.persistence.MapDrivenDataStore.getObjectCount
05-03 16:16:39.971 3604-3604/com.examples.contact W/dalvikvm: VFY: unable to resolve static method 20982: Ljava/util/Objects;.requireNonNull (Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;
05-03 16:16:39.971 3604-3604/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x71 at 0x0006
05-03 16:16:39.971 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to find class referenced in signature (Ljavax/servlet/http/HttpSession;)
05-03 16:16:39.971 3604-4078/com.examples.contact I/dalvikvm: Could not find method javax.servlet.http.HttpSession.getAttribute, referenced from method weborb.util.ThreadContext.getCallerCredentials
05-03 16:16:39.971 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve interface method 21149: Ljavax/servlet/http/HttpSession;.getAttribute (Ljava/lang/String;)Ljava/lang/Object;
05-03 16:16:39.971 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x72 at 0x0008
05-03 16:16:39.971 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to find class referenced in signature (Lweborb/security/Credentials;)
05-03 16:16:39.971 3604-4078/com.examples.contact E/dalvikvm: Could not find class ‘javax.servlet.http.HttpServletRequest’, referenced from method weborb.util.ThreadContext.getContext
05-03 16:16:39.971 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve check-cast 2730 (Ljavax/servlet/http/HttpServletRequest;) in Lweborb/util/ThreadContext;
05-03 16:16:39.971 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
05-03 16:16:39.971 3604-4078/com.examples.contact E/dalvikvm: Could not find class ‘javax.servlet.http.HttpServletRequest’, referenced from method weborb.util.ThreadContext.getHttpRequest
05-03 16:16:39.976 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve check-cast 2730 (Ljavax/servlet/http/HttpServletRequest;) in Lweborb/util/ThreadContext;
05-03 16:16:39.976 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
05-03 16:16:39.976 3604-4078/com.examples.contact E/dalvikvm: Could not find class ‘javax.servlet.http.HttpServletResponse’, referenced from method weborb.util.ThreadContext.getHttpResponse
05-03 16:16:39.976 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve check-cast 2731 (Ljavax/servlet/http/HttpServletResponse;) in Lweborb/util/ThreadContext;
05-03 16:16:39.976 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
05-03 16:16:39.976 3604-4078/com.examples.contact E/dalvikvm: Could not find class ‘javax.servlet.http.HttpSession’, referenced from method weborb.util.ThreadContext.getHttpSession
05-03 16:16:39.976 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve check-cast 2732 (Ljavax/servlet/http/HttpSession;) in Lweborb/util/ThreadContext;
05-03 16:16:39.976 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
05-03 16:16:39.976 3604-4078/com.examples.contact E/dalvikvm: Could not find class ‘javax.servlet.http.HttpSession’, referenced from method weborb.util.ThreadContext.getHttpSessionId
05-03 16:16:39.976 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve check-cast 2732 (Ljavax/servlet/http/HttpSession;) in Lweborb/util/ThreadContext;
05-03 16:16:39.976 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
05-03 16:16:39.976 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to find class referenced in signature (Lweborb/security/Credentials;)
05-03 16:16:39.976 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve instance field 10411
05-03 16:16:39.976 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x54 at 0x0006
05-03 16:16:39.976 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to find class referenced in signature (Lweborb/security/Credentials;)
05-03 16:16:39.976 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve instance field 10412
05-03 16:16:39.976 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x54 at 0x0006
05-03 16:16:39.976 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to find class referenced in signature (Lweborb/security/Credentials;)
05-03 16:16:39.976 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to find class referenced in signature (Ljavax/servlet/http/HttpSession;)
05-03 16:16:39.976 3604-4078/com.examples.contact I/dalvikvm: Could not find method javax.servlet.http.HttpSession.removeAttribute, referenced from method weborb.util.ThreadContext.setCallerCredentials
05-03 16:16:39.976 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve interface method 21151: Ljavax/servlet/http/HttpSession;.removeAttribute (Ljava/lang/String;)V
05-03 16:16:39.976 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x72 at 0x000b
05-03 16:16:39.976 3604-4078/com.examples.contact I/dalvikvm: Could not find method javax.servlet.http.HttpSession.setAttribute, referenced from method weborb.util.ThreadContext.setCallerCredentials
05-03 16:16:39.976 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve interface method 21152: Ljavax/servlet/http/HttpSession;.setAttribute (Ljava/lang/String;Ljava/lang/Object;)V
05-03 16:16:39.976 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x72 at 0x0011
05-03 16:16:39.976 3604-4078/com.examples.contact I/dalvikvm: Could not find method weborb.dispatch.Invoker.handleInvoke, referenced from method weborb.v3types.ReqMessage.execute
05-03 16:16:39.976 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve static method 21769: Lweborb/dispatch/Invoker;.handleInvoke (Lweborb/message/Message;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;
05-03 16:16:39.976 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x71 at 0x0073
05-03 16:16:39.981 3604-4078/com.examples.contact I/dalvikvm: Could not find method weborb.protocols.wolf.RequestParser.instance, referenced from method weborb.util.io.Serializer.fromBytes
05-03 16:16:39.981 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve static method 22261: Lweborb/protocols/wolf/RequestParser;.instance ()Lweborb/protocols/wolf/RequestParser;
05-03 16:16:39.981 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x71 at 0x0082
05-03 16:16:39.986 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to find class referenced in signature (Lweborb/service/WebORBCacheAttribute;)
05-03 16:16:39.986 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to find class referenced in signature (Lweborb/util/cache/Arguments;)
05-03 16:16:39.986 3604-4078/com.examples.contact E/dalvikvm: Could not find class ‘weborb.service.cacheinvalidatorevent.CacheInvalidator’, referenced from method weborb.util.cache.Cache.ensureSubscription
05-03 16:16:39.986 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve new-instance 3048 (Lweborb/service/cacheinvalidatorevent/CacheInvalidator;) in Lweborb/util/cache/Cache;
05-03 16:16:39.986 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x22 at 0x000b
05-03 16:16:39.986 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to find class referenced in signature (Lweborb/service/WebORBCacheAttribute;)
05-03 16:16:39.986 3604-4078/com.examples.contact I/dalvikvm: Could not find method weborb.service.WebORBCacheAttribute.cacheScope, referenced from method weborb.util.cache.Cache.getTarget
05-03 16:16:39.986 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve interface method 22548: Lweborb/service/WebORBCacheAttribute;.cacheScope ()Lweborb/service/SimpleParameterAnnotation$CacheScope;
05-03 16:16:39.986 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x72 at 0x0000
05-03 16:16:39.986 3604-4078/com.examples.contact E/dalvikvm: Could not find class ‘weborb.service.ICacheInvalidator’, referenced from method weborb.util.cache.Cache.getValue
05-03 16:16:39.986 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve const-class 3044 (Lweborb/service/ICacheInvalidator;) in Lweborb/util/cache/Cache;
05-03 16:16:39.986 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x1c at 0x0002
05-03 16:16:39.986 3604-4078/com.examples.contact E/dalvikvm: Could not find class ‘weborb.service.WebORBCacheAttribute’, referenced from method weborb.util.cache.Cache.getValue
05-03 16:16:39.986 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve const-class 3047 (Lweborb/service/WebORBCacheAttribute;) in Lweborb/util/cache/Cache;
05-03 16:16:39.986 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x1c at 0x0019
05-03 16:16:39.986 3604-4078/com.examples.contact E/dalvikvm: Could not find class ‘weborb.service.WebORBCacheAttribute’, referenced from method weborb.util.cache.Cache.invalidateCache
05-03 16:16:39.986 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve const-class 3047 (Lweborb/service/WebORBCacheAttribute;) in Lweborb/util/cache/Cache;
05-03 16:16:39.986 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x1c at 0x000b
05-03 16:16:39.986 3604-4078/com.examples.contact E/dalvikvm: Could not find class ‘weborb.service.WebORBCacheAttribute’, referenced from method weborb.util.cache.Cache.saveValue
05-03 16:16:39.986 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve check-cast 3047 (Lweborb/service/WebORBCacheAttribute;) in Lweborb/util/cache/Cache;
05-03 16:16:39.986 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x1f at 0x000a
05-03 16:16:39.986 3604-4078/com.examples.contact D/dalvikvm: DexOpt: unable to opt direct call 0x5816 at 0x0d in Lweborb/util/cache/Cache;.ensureSubscription
05-03 16:16:39.986 3604-4078/com.examples.contact D/dalvikvm: DexOpt: unable to opt direct call 0x5818 at 0x14 in Lweborb/util/cache/Cache;.ensureSubscription
05-03 16:16:39.986 3604-4078/com.examples.contact I/dalvikvm: DexOpt: unable to optimize static field ref 0x28ad at 0x04 in Lweborb/util/cache/Cache;.getTarget
05-03 16:16:39.991 3604-4078/com.examples.contact I/dalvikvm: DexOpt: unable to optimize static field ref 0x28ae at 0x0d in Lweborb/util/cache/Cache;.getTarget
05-03 16:16:39.991 3604-4078/com.examples.contact D/dalvikvm: DexOpt: unable to opt direct call 0x58b9 at 0xc5 in Lweborb/util/cache/Cache;.getValue
05-03 16:16:39.991 3604-4078/com.examples.contact I/dalvikvm: DexOpt: unable to optimize instance field ref 0x28d6 at 0xca in Lweborb/util/cache/Cache;.getValue
05-03 16:16:39.991 3604-4078/com.examples.contact D/dalvikvm: DexOpt: unable to opt direct call 0x58ba at 0x5a in Lweborb/util/cache/Cache;.invalidateCache
05-03 16:16:39.991 3604-4078/com.examples.contact D/dalvikvm: DexOpt: unable to opt direct call 0x58c4 at 0x6b in Lweborb/util/cache/Cache;.saveValue
05-03 16:16:40.591 3604-3605/com.examples.contact D/dalvikvm: GC_CONCURRENT freed 292K, 14% free 9457K/10940K, paused 6ms+6ms, total 49ms
05-03 16:16:40.916 3604-4078/com.examples.contact E/dalvikvm: Could not find class ‘java.beans.BeanInfo’, referenced from method weborb.reader.AnonymousObject.setFieldsAsBean
05-03 16:16:40.916 3604-4078/com.examples.contact W/dalvikvm: VFY: unable to resolve check-cast 2488 (Ljava/beans/BeanInfo;) in Lweborb/reader/AnonymousObject;
05-03 16:16:40.916 3604-4078/com.examples.contact D/dalvikvm: VFY: replacing opcode 0x1f at 0x001f
Make sure to compile the code with JDK 1.8, looks like you have a rather old version of the compiler.
Backendless Server error 1023.
Sorry, it means nothing in the context of your question.
Hi, Bryon.
Could you try to make api call to Backendless data service from simple java app and without any whereClause?
For example: “Backendless.Data.of( <table_name> ).find()”
Do you receive your data?
This code runs, but I don’t know how to assign a variable to the found data.Backendless.Persistence.of( “Table” ).findFirst( new AsyncCallback<Map>(){
@Override
public void handleResponse( Map tableObjects ) {
Log.i("Contact", "Retrieved " + tableObjects.size() + " objects from Table in Backendless");
Toast.makeText(FindActivity.this, "Retrieved "+tableObjects.size() +" objects from Table in Backendless", Toast.LENGTH_LONG).show();
}
@Override
public void handleFault( BackendlessFault fault )
{
Log.e( "MYAPP", "Server reported an error " + fault.getCode() );//compile error at 'getMessage'
Toast.makeText(FindActivity.this,"Backendless Server reported an error "+ fault.getCode(), Toast.LENGTH_LONG).show();
}
});
When the following callback is executed, the found object is the argument of the method. So in your case:
public void handleResponse( Map tableObjects )
The found object is in the “tableObjects” argument.
The code below ran and my Toast said, ‘Retrieved 10 objects from Table in Backendless.’
Backendless.Persistence.of( “Table” ).findFirst( new AsyncCallback<Map>(){
@Override
public void handleResponse( Map tableObjects ) {
Log.i("Contact", "Retrieved " + tableObjects.size() + " objects from Table in Backendless");
Toast.makeText(FindActivity.this, "Retrieved "+tableObjects.size() +" objects from Table in Backendless", Toast.LENGTH_LONG).show();
}
@Override
public void handleFault( BackendlessFault fault )
{
Log.e( "MYAPP", "Server reported an error " + fault.getCode() );
Toast.makeText(FindActivity.this,"Backendless Server reported an error "+ fault.getCode(), Toast.LENGTH_LONG).show();
}
});
The below code did not have any compile errors, but it had a runtime error that force-closed the app on my device.
Backendless.Persistence.of( “Table” ).find( new AsyncCallback<List<Map>>(){
@Override
public void handleResponse( List<Map> tableObjects )
{
// every loaded object from the “Table” table is now an individual java.util.Map
Log.i(“Contact”, “Retrieved " + tableObjects.size() + " objects from Table in Backendless”);
Toast.makeText(FindActivity.this, “Retrieved “+tableObjects.size() +” objects from Table in Backendless”, Toast.LENGTH_LONG).show();
}
@Override
public void handleFault( BackendlessFault fault )
{
// an error has occurred, the error code can be retrieved with fault.getCode()
Log.e( “MYAPP”, "Server reported an error " + fault.getCode() );
Toast.makeText(FindActivity.this,"Backendless Server reported an error "+ fault.getCode(), Toast.LENGTH_LONG).show();
}
});
The code below ran, but had a Backendless server error. I do have a table named “Contact” and a column named “age” which contains data “47”.
String whereClause = “age = 47”;
DataQueryBuilder queryBuilder = DataQueryBuilder.create();
queryBuilder.setWhereClause( whereClause );
Backendless.Data.of( “Contact” ).find( queryBuilder, new AsyncCallback<List<Map>>(){
@Override
public void handleResponse( List<Map> foundContacts )
{
// every loaded object from the “Contact” table is now an individual java.util.Map
}
@Override
public void handleFault( BackendlessFault fault )
{
// an error has occurred, the error code can be retrieved with fault.getCode()
}
});
Please be sure to specify what error you got. Without it, there is nothing that we could do to assist you.
When I run this code I get the error that follows.
//this code-block has runtime error that closes app on device
Backendless.Data.of( “Table” ).find( new AsyncCallback<List<Map>>(){
@Override
public void handleResponse( List<Map> tableObjects )
{
// every loaded object from the “Table” table is now an individual java.util.Map
}
@Override
public void handleFault( BackendlessFault fault )
{
// an error has occurred, the error code can be retrieved with fault.getCode()
Log.e( “MYAPP”, "Server reported an error " + fault.getCode() );
Toast.makeText(FindActivity.this,"Backendless Server reported an error "+ fault.getCode(), Toast.LENGTH_LONG).show();
}
});
05-05 06:37:06.901 21676-21680/com.examples.contact D/dalvikvm: GC_CONCURRENT freed 331K, 14% free 9609K/11132K, paused 2ms+3ms, total 30ms
05-05 06:37:07.181 21676-21676/com.examples.contact D/AndroidRuntime: Shutting down VM
05-05 06:37:07.181 21676-21676/com.examples.contact W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40ce8960)
05-05 06:37:07.191 21676-21676/com.examples.contact E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.ClassCastException: java.util.HashMap[] cannot be cast to java.util.List
at com.examples.contact.FindActivity$2.handleResponse(FindActivity.java:50)
at com.backendless.async.message.AsyncMessage$ResponseHandler.handle(AsyncMessage.java:64)
at com.backendless.async.message.AsyncMessage.handleCallback(AsyncMessage.java:41)
at com.backendless.core.AndroidCarrier$1.handleMessage(AndroidCarrier.java:37)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5365)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Yesterday I updated Java and Android Studio.