last day (15 days later) » 

8:13 AM
0
Q: Terminating app due to uncaught exception 'NSRangeException', reason: -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' - 2

Mishal Awanworking as a new person in json i want to show data in tableview cell but when i am populating my table view cell it is giving an exception mentioned above. i had asked this question previously but not get exact solution may b i can not explain properly so i am sharing my demo project. https://ww...

 
In inboxmessagesGetSuccess method, add first line as NSLog (@"Count %d", [[response objectForKey:@"messageResponse"] length] ); Also print the value in messageResponse key and update the question. Then it would be easy to identify. As of now I guess issue is there in response dict only.
 
in first array 2o objects are coming . and in inboxmessages array message id is populating but when i populate with tableview cell it is giving an exception.
 
In numberofrows tableview datasource method whats the count coming, is it also 2?
 
no it is 15 u can check my attached project
may i am doing some stupid mistake thst y i attached my pjct with it..
 
valuedate.text=[[self.inboxmessagesarray objectAtIndex: 15 ]objectForKey:@"messageId"]; -- how would this work then, if array size is 2.
Hope you are getting my point here. What I am trying to explain?
 
8:14 AM
yeah am checking
wil you please check my attached project if i change numberofrows in section then many other problems will occur
as i am using check boxes in it
 
Ok let me check that as well
 
ok then do tell me that what i am mistaking...
 
What type of project this is? I am whats the actual goal of the project?
 
to show messages of users in tableview
just want to show messages in tableview cell ... response is coming correct but unable to populate it in tableview
 
Ok wait a min I am checking
 
8:18 AM
ok thanx
as i need it very urgent and stuck many times... in it
 
hmmm I will try to help. I am starting my mac machine to check your code. So it might take a while
 
ok ok
i can wait
 
where are you from?
 
rawalpindi
pakista
pakistan
u?
 
for me tableview is loaded perfectly
now what should i do?
 
8:26 AM
i want to populate array message id in tableview cell for row indexpath
i had commented it
 
Ok
 
u can check array
 
hi there?
 
yes
did u find error ?
 
yup
first thing - don't use lblArray at all
how would you know that whether there are 15 objects or more or less
you have hardcoded that with 15 objects in viewdidload
 
8:37 AM
hmm then
 
in cell for row method
 
yes ?
 
valuedate.text = [[self.inboxmessagesarray objectAtIndex:indexPath.row] objectForKey:@"messageId"];
in numberofrowsinsection method
 
it is runnuing ?
 
return self.inboxmessagesarray.count;
try this three changes
and let me know ...
 
8:40 AM
did u make it?
it is working fine?
 
haa na
aap try to karo
because you actually know whats project requirement
 
listen
 
and muje pata nahi chala ki from where this data is coming
hmmm
 
apne wo method dekha hai id)inboxmessagesGetSuccess:(FBGenericWebHandler*)handler response:(NSDictionary*)response
this one
 
that is perfect
no issue in that
 
8:43 AM
is mn jo array hain na
 
hmm
 
first array
us mn 20 objects hain
right?
 
yes
 
i just want to show that 20 objects message id in table view
smjh a gai appko ?
 
wahi
aap mere wale changes add to karo
 
8:44 AM
ok 1 sec
 
I have used the same array only everywhere in code line, if you have checked the lines I sent over chat
just replace these lines and try
 
ok i am checking
nothing happens an empty view is showing
 
:o
 
will you check in the project i had attached ?
?
?
 
wait
//
// FbinboxViewController.m
// FretBay
//
// Created by Saba Awan on 02/11/2014.
// Copyright (c) 2014 lecodeur. All rights reserved.
//

#import "FbinboxViewController.h"
#import "FBGenericWebHandler.h"


@interface FbinboxViewController ()

@end

@implementation FbinboxViewController
@synthesize checkimageArray,lblArray;
@synthesize morebtn,archievebtn,searchbtn,deletebtn,Menu,selectionlbl,inboxmessagesarray;

- (void)viewDidLoad {
[super viewDidLoad];
[inboxmessagesarray removeAllObjects];
 
8:49 AM
ok
 
copy entire thing and paste it to your file
 
ok let me check
 
note: I have removed commented code for my purpose
so first have back up of your code
 
ok fine
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 15 beyond bounds
when i scroll down table view
?
 
have you copy pasted entire my code?
 
8:53 AM
yeah
u will send change project here
scroll down table view and check
is it working fine or not
 
oh there is one if condition in cellforrowatindexpath which is usin self.lblArray
 
then ?
 
dont use self.lblArray .. I have told you no
its hard coded with 15 objects in view did load method
you have written hardcoded for loop
which is bad coding
 
then lblarray ki jaga inboxmessage array use krn ?
?
 
whats use of lblArray
 
8:58 AM
for the purpose of checkboxes
u can in selector method
-(IBAction)checkButton:(UIButton *)sender
in this method
 
ok
remove that for loop from view did load firstly
 
ok
then
 
-(void)inboxmessagesGetSuccess:(FBGenericWebHandler*)handler response:(NSDictionary*)response
{
NSMutableArray *inboxArray = [[NSMutableArray alloc] init];
NSArray *firstarray=[[[response objectForKey:@"messageResponse"] objectAtIndex:1] objectForKey:@"messages"];
for(NSDictionary *tmp in firstarray)
{
NSMutableDictionary *messages=[[NSMutableDictionary alloc]init];
[messages setValue:[tmp objectForKey:@"messageId"] forKey:@"messageId"];
[self.inboxmessagesarray addObject:messages];
}

for (int i=0; i<self.inboxmessagesarray.count; i++)
change this method
I have added that loop in this method
 
ok ok let me check
it is working
what i am mistaking
 
enjoy coding :)
 
9:03 AM
u can post solution in SO as well
 
ok will do
 
thanks for ur time
 
Added in answer but in short
 
9:59 AM
There
 

  last day (15 days later) »