Getting ArrayList from Custom Code

0 votes

Hi,

I have created a custom coded jar. It has an array which contains some of messages from buddies of a user. I deployed it, on tests everyting went fine.

I got response and traced well. But when I want to get response as array, there is a problem.

On server side; 

ArrayList<Buddy> buddies = getMessagesOfUser(messageIds);
JSONObject jsonResponse = new JSONObject();
jsonResponse.put("buddies",buddies.toString());
On client side; ( I am using AS3 API)
var array:Array = new BuddyResponseBuilder().buildArrayResponse(response.buddies);
I got error :
 
TypeError: Error #1009: Cannot access a property or method of a null object reference.
 
at com.shephertz.app42.paas.sdk.as3::App42ResponseBuilder/getServiceJSONObject()[E:\Samita_work\gitProject_API\App42_Flash_API_Desktop\App42_ActionScript_API\src\com\shephertz\app42\paas\sdk\as3\App42ResponseBuilder.as:18]
 
at com.shephertz.app42.paas.sdk.as3.buddy::BuddyResponseBuilder/buildArrayResponse()[E:\Samita_work\gitProject_API\App42_Flash_API_Desktop\App42_ActionScript_API\src\com\shephertz\app42\paas\sdk\as3\buddy\BuddyResponseBuilder.as:32]
 

How can I solve that?

 

Thanks,

asked Sep 13, 2014 in App42 Cloud API-BaaS by Tufan (64 points)
recategorized Mar 3, 2015 by sushil
Can you just parse only for first element and check if it works? Something like this.

var array:Array = new BuddyResponseBuilder().buildArrayResponse(response.buddies[0]);
nope. I received  property 0 not found on String error.

1 Answer

0 votes

Hello,

 
On the server side, when you are putting the value in json object update the code snippet with below code: 
 
ArrayList<Buddy> buddies = getMessagesOfUser(messageIds);
JSONObject jsonResponse = new JSONObject();
jsonResponse.put("buddies",buddies.get(0).toString());
 
And fetch it back in your app using the below code snippet:
 
var buddyMessageArray:Array = new BuddyResponseBuilder().buildArrayResponse(jsonResponse["buddies"]);
 
let us know if it helps.
 
Thanks 
HImanshu Sharma

 

answered Sep 16, 2014 by hs00105 (2,005 points)
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...