I am currently using the latest verion of Adobe Flash Builder to create a Mobile Application. For the application one feature is to allow the users to bookmark content an this is done by storing the id of the object to be Bookmarked into an SQLite db on the device. This part has been done successfully and they are stored fine.
Now what I want to do is to pull back the bookmarked id's from the database and pass them to a WebService call which needs to be made to an External Database. When I retrieve the Bookmark id's from the local database they are contained within object, I now need to find a way to take the id's from the database objects in the ArrayCollection and store them in a new array that will be passed to the WebService, as the webservice is expecting an Array of Int's and not Objects. Below is the code I created to see if the object items are within the array list of objects:
private function loop():void
{
var index:int;
for( index = 0; index < compsCollection.length; index++ )
{
trace( "Element " + index + " is " + compsCollection[index].comp_id );
}
}
Now when I test the app all seems fine and the trace statement returns the following:
Element 0 is 91
Element 1 is 9
Element 2 is 9
Element 3 is 9
Element 4 is 9
Element 5 is 9
Element 6 is 9
Element 7 is 282
Element 8 is 282
Element 9 is 282
Element 10 is 282
Element 11 is 282
Element 12 is 282
However I then tried to populate the Int values for each of the objects into a new array using the code below:
var ids:Array;
var index:int;
for( index = 0; index < compsCollection.length; index++ )
{
trace( "Element " + index + " is " + compsCollection[index].comp_id );
ids.push(compsCollection[index].comp_id);
}
}
However when I run this code I get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
This error occurs on line:
ids.push(compsCollection[index].comp_id);
I do not understand why i am getting this error, can anyone please help?? Thanks
While I don't know anything about Adobe Flash Builder, generally you have to instantiate an array before using it.
var ids:Array = [];
maybe?? (As RIAstar suggested)
Related
When i run my app it crash with this phrase ( sorry for bad English )
I tried a lot to resolve this problem but i cant
gridLayout.getChildAt return null as the message says.
Try changing your condition with gridLayout.getchildCount()-1
You are looping until the gridlayout childCount and array indices start at 0 in kotlin.
So if you have an array of 10 elements, to access the first element you index it like array[0], for the second element you use array[1] and so on. So if you try to access array[10] that means you are trying to get the 11th element which doesn't exist as your array has a total of 10 elements. The last element in this example array is at index 9 so you access it by calling array[9].
In your case by looping until gridLayout.getChildCount(), when the loop reaches the last element it will try to access an element that doesn't exist in the array.
So you should loop until gridLayout.getChildCount() - 1 because that's the correct index for the last element.
I'm trying to populate an array with files in my raw folder. I then pick a random slot in that array and use it to play that file.
But when I do this, every slot seems to contain whatever was the final video in the array. I'm not sure what the cause of this is...
var videos = Array(5){R.raw.c0; R.raw.c1; R.raw.c2; R.raw.c3; R.raw.c4};
videoView.setVideoPath("android.resource://" + getPackageName() + "/" + videos[Random.nextInt(0, 4)])
videoView.requestFocus()
videoView.start()
You're initializing the array incorrectly.
The {...} block after the Array(5) is actually a lambda that takes an integer and returns the content for that index in the array. The semicolons (rather than commas) mean that each of R.raw.c0, R.raw.c1, etc. is just a statement that doesn't do anything. Since R.raw.c4 is the last statement in that block, it sets all five indexes to that value.
You probably meant:
val videos = intArrayOf(R.raw.c0, R.raw.c1, R.raw.c2, R.raw.c3, R.raw.c4)
Note the replacement of semicolons with commas. I also switched the var to a val, as you don't appear to be changing it.
You should be doing one of the following to correctly create your array.
var videos = intArrayOf(R.raw.c0, R.raw.c1, R.raw.c2, R.raw.c3, R.raw.c4)
or
var videos = arrayOf(R.raw.c0, R.raw.c1, R.raw.c2, R.raw.c3, R.raw.c4)
Please try it, this should solve your problem.
I have a list which looks something like this:
indices = [ image_02, image_32, image_33 ]
I am using flutter_secure_storage package to store data such that every element in the above list has some data stored like this:
image_02 :
{
image: "http://path//to//image//",
link: "http://links//to//webpage//"
}
To access the data I use:
var image_data = await storage.read(key: 'image_02');
Using this method, I can get the data stored in 'image_02' in the secure_storage.
However, I have over a few hundred data like this. Which is why, I have a list of indices that maintains a list of keys to access the stored data.
Now, I used for loop to iterate through the list like this:
for (var index in list) {
var data = await storage.read(key: index);
print(data);
}
But the for loop only returns the first data. All the other results are null:
I/flutter (15384): {image: https://xxxxxxxxxxx.com/api/upload/image_slider/f323694602724b675a898ba0454561ee.png, link: https://www.xxxxxxx.com/watch?v=xxxxxxxxxxx}
I/flutter (15384): null
I/chatty (15384): uid=11004(com.xxxxxx.xxxxxx) Thread-3 identical 5 lines
I/flutter (15384): null
For now, I am working on test server, which has around 6 - 7 images. Is there any way to loop through a list and get data from a function that returns a future?
I apologize for my English, I use Google translator.
The question is: how can I get the value of a particular column of a particular row. As an example - there are two columns "cost" and the "margin" in the database options scored 10 lines, how can I get a "cost" in line 5?
When I do so -
SaveData item = SaveData.findById(SaveData.class, 5);
Log.d(LOG_TAG, String.valueOf(item.cost));
then I crash
It is the correct way to retrieve objects providing their identifier. However the "5" represents the object of type SaveData which the identifier is equal to 5, and not the #5 row.
So, check which is the identifier of the object you want to retrieve, or alternatively, get all the objects stored in the database and the select the #5 row as follows (the code is to be considered as a sample, check it before to try)
List<SaveData> list = SaveData.listAll(SaveData.class);
if (list.size() > 4) { // it means that there are at lease 5 elements
return list.get(4); //it retrieves the #5 element of the list/database
}
I have a JSONArray in an Android application that has the following entries, for instance,
[start : 0.100 , stop : 2.312]
[start : 2.313 , stop : 4.565]
[start : 4.566 , stop : 7.898]
...
...
...
[start 85.123 , stop : 97.659]
now giving a value = 86.235, I want to get the index of which this number is greater than and less than
start <= value <= stop
without traversing the entire array each time I want to look for an entry? Is this possible by mapping this to a different data structure or do I have to traverse the array each time to figure out which item in the array this is greater than and less than?
If it is sorted. The fastest would be Binary Search. That meets the requirment of
without traversing the entire array each time I want to look for an
entry?
Since O (logn) < n .