Alok Vishwakarma
Alok Vishwakarma

Reputation: 48

getting exception 'NSInvalidArgumentException', reason: '-[__NSCFString stringValue]

I have all ready tried multiple solution by doing Google, but i am getting two kind of error, with solution i am getting this

2015-08-06 18:52:33.110 FastFast[2824:110493] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString stringValue]: unrecognized selector sent to instance 0x7f89c1eb7e50' * First throw call stack:

But when i am not applying any solution then i am getting this

2015-08-06 19:09:24.473 FastFast[2933:117451] -[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000003 2015-08-06 19:09:24.480 FastFast[2933:117451] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000003' * First throw call stack:

i am messing with this code since 1 day but not able to find the actual problem. but when ever i set static limit on this function, every thing is works fine.

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSLog(@"Number Of Row  %lu",_AddressArray.count);
return 4; // when set static limit here like this all works fine 
return [self.temporaryAddArray count];}

below link belongs to my interface file and implementation file

file.h https://drive.google.com/file/d/0B85GTvLEHASFVDEwajA1YXp1aUE/view?usp=sharing

file.m https://drive.google.com/file/d/0B85GTvLEHASFNEhzUnN1U25qaEk/view?usp=sharing

any kind of help will be appreciated.

Upvotes: 0

Views: 1264

Answers (4)

Alok Vishwakarma
Alok Vishwakarma

Reputation: 48

Fianlly after very deep digging, with the help of your answers, i short it out where was the problem.

Json responce is here {"Android":[{"recip_code":"94541824","recip_fname":"","recip_lname":"","recip_add1":"hillsrtreat main road h.no. 3535","recip_img":"","recip_add2":"","recip_stateid":"new state","recip_cityid":"Dublin","result":"Success"},{"recip_code":"53843299","recip_fname":"","recip_lname":"","recip_add1":"rz x yes RR HDTV j deed ju","recip_img":"","recip_add2":"","recip_stateid":"Westmeath","recip_cityid":"Dublin","result":"Success"},{"recip_code":"11493834","recip_fname":"","recip_lname":"","recip_add1":"newdgbfh","recip_img":"","recip_add2":"","recip_stateid":"Westmeath","recip_cityid":"bobo2","result":"Success"},{"recip_code":"29376578","recip_fname":"","recip_lname":"","recip_add1":"edggvfhkyfv","recip_img":"","recip_add2":"","recip_stateid":"Dublin","recip_cityid":"bobo2","result":"Success"},{"recip_code":"22549638","recip_fname":"","recip_lname":"","recip_add1":"This ios address 34 street","recip_img":"","recip_add2":"","recip_stateid":0,"recip_cityid":0,"result":"Success"}]}

Image Link of json analysis

In given image there is a visualization of error in array, in 1st selection it shows an STRING and in 2nd selection there is integer value which is the reason of that brutal exception

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"addAddress";
AddressTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier     forIndexPath:indexPath];
@try {


    NSDictionary *currentAddress = [self.AddressArray  objectAtIndex:indexPath.row];
    NSString *addTitle= [NSString stringWithFormat:@"%@%@",[currentAddress objectForKey:@"recip_add1"],[currentAddress objectForKey:@"recip_add2"]];

    cell.lblAddress.text =addTitle;
    cell.lblCity.text=[currentAddress objectForKey:@"recip_cityid"];
    cell.lblRecipentCode.text=[currentAddress objectForKey:@"recip_code"];
// cell.lblState.text=[NSString stringWithFormat:@"%@",[[currentAddress objectForKey:@"recip_stateid"] stringValue]];
    cell.lblState.text=[currentAddress objectForKey:@"recip_stateid"];

}
@catch (NSException *exception) {
    NSLog(@" Exception hit %@",exception);
}



return cell;
}

every thing works fine till (NSDictionary *currentAddress) return string value, but at point where cell.lblCity.text interact with Integr value it show exception.

thanks guys to give your important time and answer :)

Upvotes: 0

Adarsh G J
Adarsh G J

Reputation: 2684

self.temporaryAddArray = [tempAddress objectForKey:@"Android"];

Here is the problem...

  • first you check [tempAddress objectForKey:@"Android"] contain array value From your error i thinks [tempAddress objectForKey:@"Android"] return a string value thats why this throw error..

Make sure that [tempAddress objectForKey:@"Android"] return NaArray value after that load the tableview.

Do this it will solve your issue.

[AFRequestmanager POST:tempUrlAddress parameters:urlParams success:^(AFHTTPRequestOperation *operation, id responseObject) {

         NSLog(@"Responce Parameter %@",responseObject);

        NSDictionary *tempAddress= (NSDictionary *)responseObject;

        [self.activityIndicatorView stopAnimating];

id android = [tempAddress objectForKey:@"Android"];
if (if([android isKindOfClass:[NSArray class]]){
    //Is array
       self.temporaryAddArray =[android mutableCopy];
        [self.tableview reloadData];
}

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

         NSLog(@"Errorsss parameters %@",error);
    }];

Upvotes: 0

Ben Avery
Ben Avery

Reputation: 1724

You need to make sure you are initialising your NSMutableArray

Simply adding

self.temporaryAddArray = [[NSMutableArray alloc]init];

to

-(void)viewDidLoad;

should fix your issue.

Upvotes: 1

Grzegorz Krukowski
Grzegorz Krukowski

Reputation: 19822

I'm afraid your values are not at the type you expect them to be. Looks like "temporaryAddArray" is NSNumber not an array and something else is not NSNumber but it's NSString. Before you assign values from JSON using objectForKey: check their types by displaying:

NSLog(@"%@", [variable class]);

And make sure that they have expected type in your JSON, because some of them don't. It would help if you paste JSON you get from API then I can point out problem exactly.

Upvotes: 1

Related Questions