views:

59

answers:

2

Getting error in this line , NSString *nmm =[narr objectAtIndex:1];

error shows: 'NSRangeException', reason: '* -[NSCFArray objectAtIndex:]: index (1) beyond bounds (1)'

+1  A: 

It looks like your array only got one value (which you can accesss at index 0, not index 1).

unset
Yup...Thanks. this shows data but i m not able to assign to textbox.code here..NSString *nmm =[narr objectAtIndex:0]; nametxt.text=???; this nmm holds name,lname and id,i want to show it in textboxes
xcodemaddy
`nmm` is an `NSString`, so if it holds the `name`, `lname` and `id`, you'll need to extract those from `nmm` in some way. But we can't help you with that as we don't know the format of this `nmm`.
Douwe Maan
again i m getting sane error when assign to textbox from objectAtIndex:0
xcodemaddy
A: 

You should probably start by checking the contents of narr at run time. It sounds like the contents aren't what you would expect them to be at the desired point in execution. Right before the line you posted in your question, use an NSLog call to log the contents of the array like this:

NSLog(@"Contents of array: %@", narr);

Then run the app and check the console after the error arises. Put some time into learning how to use NSLog, breakpoints, and the GDB console - they will end up saving you lots of frustration when debugging.

Your comments on unset's answer raise another point: Why are you storing multiple pieces of data inside the same string? Wouldn't it be easier to separate name, lname and id into separate strings and place each into its own array cell? Then you could access them using [narr objectAtIndex:] without having to worry about parsing the string every time you need one of those pieces of information.

Endemic
NSMutableArray *narr=[[NSMutableArray alloc]initWithArray:[my readItems:n]];im fetching data from database in "readItems" in another class. this returns array which i m storing it in 'narr' in this class.Now i want display data which is in 'narr'.im getting error here [narr objectAtIndex:1].
xcodemaddy
I understand what you're trying to do, but you're getting an out-of-bounds error, which means that the array `narr` almost definitely does not contain what you think it does. Using the NSLog method I described will allow you to actually see the contents of that array at run time. Seeing as you commented earlier (under unset's answer) that a call to [narr objectAtIndex:0] gives the same error, I'm guessing that `narr` is probably empty, and the bug lies in its initialization.
Endemic