-2
It is showing exception (signal sigabert) at  return UIApplicationMain(argc, argv, nil, NSStringFromClass([xyzAppDelegate class]));

EXCEPTION DETAIL IS: 2015-02-19 13:09:02.825 try11feb2[377:11303] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil' *** First throw call stack: (0x1c92012 0x10cfe7e 0x1c45b6a 0x1c45a20 0x26ab 0xbd5589 0xbd3652 0xbd489a 0xbd360d 0xbd3785 0xb20a68 0x46156dc 0x4613bb3 0x4651cda 0x1c348fd 0x465235c 0x46522d5 0x453c250 0x1c15f3f 0x1c1596f 0x1c38734 0x1c37f44 0x1c37e1b 0x1bec7e3 0x1bec668 0x13ffc 0x1c3d 0x1b65 0x1) libc++abi.dylib: terminate called throwing an exception (lldb)

import "xyzViewController.h"

    @interface xyzViewController ()

    @end

    @implementation xyzViewController
    @synthesize mytv;

    - (void)viewDidLoad
    {
        tabledata=[[NSMutableArray alloc]init];
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }

    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

    - (IBAction)btnpressed:(id)sender {

        NSString *str=@"http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/limit=10/json";
        NSURL *url=[[NSURL alloc]initWithString:str];
        NSURLRequest *req=[[NSURLRequest alloc]initWithURL:url];
        conn=[[NSURLConnection alloc]initWithRequest:req delegate:self];
        if (conn) {
            webdata=[[NSMutableData alloc]init];
        }

    }
    -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    {
        [webdata setLength:0];
    }
    -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {
        [webdata appendData:data];
    }
    -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
    {
        NSLog(@"failed");
    }
    -(void)connectionDidFinishLoading:(NSURLConnection *)connection
    {

        NSDictionary *ald=[NSJSONSerialization JSONObjectWithData:webdata options:0 error:Nil];
        NSDictionary *feed=[ald objectForKey:@"feed"];
        NSArray *arrayofentry=[feed objectForKey:@"entry"];
        for (NSDictionary *dic in arrayofentry)
        {  NSDictionary *zero=[dic objectForKey:0];
            NSDictionary *title=[zero objectForKey:@"title"];
            NSString *label=[title objectForKey:@"label"];

            [tabledata addObject:label];
             // NSLog(@"%@",label);}
          //  tabledata =[[NSArray alloc]initWithObjects:label, nil];
            [[self mytv]reloadData];
        }
[[self mytv]reloadData];
    }
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [tabledata count];
    }
    -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSString *cellIdentifier=@"cell";
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (!cell) {
            cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

        }
cell.textLabel.text=[tabledata objectAtIndex:indexPath.row];
        return cell;
    }
    @end
  • possible duplicate of [Xcode 4.2 SIGABRT Error](http://stackoverflow.com/questions/8748425/xcode-4-2-sigabrt-error) – Dharma Feb 19 '15 at 06:25
  • you are trying to pass a wrong key NSDictionary *zero=[dic objectForKey:0]; do you have a value in zero dictionary? you should reload your data after for loop and you should add this line cell.textLabel.text=[tabledata objectAtIndex:indexPath.row]; before returning a cell not in if condition. – karthikeyan Feb 19 '15 at 06:56
  • Sir, I have edited my code. But its not working again. – Bhupesh Sharma Feb 19 '15 at 07:53
  • what key value you need load in tableview? – karthikeyan Feb 19 '15 at 07:59
  • @karthikeyan i am parsing top ten songs name from (http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/limit=10/json"). – Bhupesh Sharma Feb 19 '15 at 09:25

1 Answers1

0

your parsing code entirely wrong.i don't know what value you need to load in table view...For example i have parsed a label key values.it may help you,just change this code.

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{

    NSDictionary *ald=[NSJSONSerialization JSONObjectWithData:webdata options:0 error:Nil];
    NSDictionary *feed=[ald objectForKey:@"feed"];
    NSArray *arrayofentry=[feed objectForKey:@"entry"];
    NSLog(@"%@",arrayofentry);
    for (NSDictionary *dic in arrayofentry)
    {
        NSDictionary *zero=[dic objectForKey:@"category"];
        NSString *label=[[zero objectForKey:@"attributes"]valueForKey:@"label"];

        [tabledata addObject:label];

    }
    [[self mtv]reloadData];
}

EDIT:

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{

    NSDictionary *ald=[NSJSONSerialization JSONObjectWithData:webdata options:0 error:Nil];
    NSDictionary *feed=[ald objectForKey:@"feed"];
    NSLog(@"%@",[feed allKeys]);
    NSArray *arrayofentry=[feed objectForKey:@"entry"];
    NSLog(@"%@",arrayofentry);
    for (NSDictionary *dic in arrayofentry)
    {
        //THIS LINE TELL YOU THAT ALL THE AVAILABLE KEYS IN DICTIONARY
        NSLog(@"%@",[dic allKeys]);

//        NSDictionary *zero=[dic objectForKey:@"category"];
//        NSString *label=[[zero objectForKey:@"attributes"]valueForKey:@"label"];


        // NSDictionary *zero=[dic objectForKey:@"title"];
        NSString *label=[[dic objectForKey:@"title"]valueForKey:@"label"];
        [tabledata addObject:label];

    }
    [[self mtv]reloadData];
}

let me know if you want parse another value..

karthikeyan
  • 3,821
  • 3
  • 22
  • 45