Dear King, "array indexing is zero-based, so you would start your loop from 0 and go to 9 (where i < 10)" Right sir, I'm aware it's for illustration and I forgot to change it.
"You've initialized an array to exactly three elements. Anything after that" This part is essential, if I do not know how many element I have then I cannot declare it predefine but declare array without value to be filled later. That is why I have a for loop to extract value from a XML field to fill into the array. But the array seems to be null unless I have pre- initialise it with something. The for loop only fill the data for dummy value I put, if I initialise 3 dummy values the for loop fill exactly 3 values and leave the rest empty. If i set set 5 dummy values, the 5 get filled correctly. Java is not my native and I have read a few java books and written full running android apps. Then, still unable to figure this out... maybe I need some beer :D On Dec 25, 11:08 am, TreKing <treking...@gmail.com> wrote: > On Fri, Dec 24, 2010 at 8:12 PM, Mystique <joven.ch...@gmail.com> wrote: > > String[] lv_arr; > > > for(int i=1; i<11; i++){ > > lv_arr[i] = "hello"; > > } > > > When I toast the value of lv_arr[i] it is null. > > If this is your actual code, you need to initialize the array. > String[] lv_arr = new String[11]; > > Second, array indexing is zero-based, so you would start your loop from 0 > and go to 9 (where i < 10). > > > > > If I do this: > > > String[] lv_arr = {"hello", hello", "hello"} + the for loop, I can get the > > hello value when I do the toast. but [3]-[10] is still null value. > > You've initialized an array to exactly three elements. Anything after that > (index 3 and above) is non-existent. > > These are really basic Java concepts. If you don't understand this, I highly > recommend you go study Java on it's own and figure this stuff out before > trying to do an Android project. You're going to run into a lot of headaches > if you try to learn both at the same time. > > --------------------------------------------------------------------------- > ---------------------- > TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago > transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en