magorik
magorik

Reputation: 47

Backendless service beyond bounds for empty NSArray

this is my code

 BackendlessDataQuery *query = [BackendlessDataQuery query];
query.whereClause = [NSString stringWithFormat:@"UniversityName LIKE \'%%%@%%\' ", partialName];
[[backendless.persistenceService of:[University class]] find:query response:^(BackendlessCollection *coll) {

    });
} error:nil];

when the third line is run i get error

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArray0 objectAtIndex:]: index 3 beyond bounds for empty NSArray' *** First throw call stack: (0x181245900 0x1808b3f80 0x1811c1478 0x10034d250 0x100318f24 0x1000ea9b0 0x101859bf0 0x101859bb0 0x10185f658 0x1811fcbb0 0x1811faa18 0x181129680 0x182638088 0x185fa0d90 0x10017d650 0x180cca8b8) libc++abi.dylib: terminating with uncaught exception of type NSException

what is the reason?

Upvotes: 2

Views: 229

Answers (2)

magorik
magorik

Reputation: 47

The reason is that i not init the Backendless..

  [backendless initApp:APP_ID secret:SECRET_KEY version:VERSION_NUM];

It to me punishment for Copy-Past... Thanks all!

Upvotes: 1

Lou Franco
Lou Franco

Reputation: 89162

The exception is because inside of the of:find:response method of the persistenceService, the code tries to get index 3 of an empty array. The most likely reason given your code is that that code has a bug with unexpected parameters.

EDIT: based on your comment, you may be running this code before backendless is configured. application: didFinishLaunchingWithOptions: might be too early.

ORIGINAL ANSWER:

  1. Remove the query.whereClause = [NSString stringWithFormat:@"UniversityName LIKE \'%%%@%%\' ", partialName]; line. Does it work then? If so, then your where clause is probably not expected (is UniversityName the correct field name? Does backendless support Like? If so, is that the correct syntax for it?)

  2. If it still doesn't work without the whereClause -- does backendless know about your University class?

If this doesn't help, it might be better to ask backendless for help.

Upvotes: 0

Related Questions