0

Getting error in this line :

NSString *nmm =[narr objectAtIndex:1];

error shows :

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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

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
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.
again i m getting sane error when assign to textbox from objectAtIndex:0
1

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.

2 Comments

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].
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.