2012-05-28 53 views
0

我想從我設置的服務器訪問數據。 雖然4個文件工作完美,我得到一個Thread2:程序接收信號:「EXC_BAD_ACCESS」。在NSString上獲取EXC_BAD_ACCESS。日誌說無效CFStringRef

-(void)loadContentInBackground 
{ 

     NSError *error; 

     NSString *posterURL = [[NSString alloc] initWithFormat:@"%@PartyCentral/WeeklyParties/Club%@/poster.jpg",baseURL,clubNum]; 

     poster.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:posterURL]]]; 

     posterEnlarged.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:posterURL]]]; 

     NSString *vp1URL = [[NSString alloc] initWithFormat:@"%@PartyCentral/WeeklyParties/Club%@/VenuePic/pic1.jpg",baseURL,clubNum]; 
     venuePic1.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:vp1URL]]]; 

     NSString *vp2URL = [[NSString alloc] initWithFormat:@"%@PartyCentral/WeeklyParties/Club%@/VenuePic/pic2.jpg",baseURL,clubNum]; 
     venuePic2.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:vp2URL]]]; 

     NSString *vp3URL = [[NSString alloc] initWithFormat:@"%@PartyCentral/WeeklyParties/Club%@/VenuePic/pic3.jpg",baseURL,clubNum]; 
     venuePic3.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:vp3URL]]]; 


     NSString *nameURL = [[NSString alloc] initWithFormat:@"%@PartyCentral/WeeklyParties/Club%@/name.txt",baseURL,clubNum]; 
     NSString *nameData = [NSString stringWithContentsOfURL:[NSURL URLWithString:nameURL] encoding:NSASCIIStringEncoding error:&error]; 
     name.text = nameData; 

     // Date Being downloaded. 
     NSString *dateURL = [[NSString alloc] initWithFormat:@"%@PartyCentral/WeeklyParties/Club%@/date.txt",baseURL,clubNum]; 
     NSString *dateData = [NSString stringWithContentsOfURL:[NSURL URLWithString:dateURL] encoding:NSASCIIStringEncoding error:&error]; 
     date.text = dateData; 

     // Day Being downloaded. THIS IS WHERE THE ERROR COMES IN HIGHLIGHTING THE 
     //initWithFormat line 


     NSString *dayURL = [[NSString alloc] initWithFormat:@"%@PartyCentral/WeeklyParties/Club%@/day.txt",baseURL,clubNum]; 
     NSString *dayData = [NSString stringWithContentsOfURL:[NSURL URLWithString:dayURL] encoding:NSASCIIStringEncoding error:&error]; 
     day.text = dayData; 

     // Latitude & Longitude Being downloaded. 
     NSString *latitudeURL = [[NSString alloc] initWithFormat:@"%@PartyCentral/WeeklyParties/Club%@/Location/latitude.txt"]; 
     NSString *latitudeData = [NSString stringWithContentsOfURL:[NSURL URLWithString:latitudeURL] encoding:NSASCIIStringEncoding error:&error]; 

     NSString *longitudeURL = [[NSString alloc] initWithFormat:@"%dPartyCentral/WeeklyParties/Club%@/Location/longitude.txt",baseURL,clubNum]; 
     NSString *longitudeData = [NSString stringWithContentsOfURL:[NSURL URLWithString:longitudeURL] encoding:NSASCIIStringEncoding error:&error]; 

     CLLocationCoordinate2D location; 
     location.latitude = [latitudeData doubleValue]; 
     location.longitude = [longitudeData doubleValue]; 

     MapAnnotation *newAnnotation = [[MapAnnotation alloc] initWithTitle:[name text] andCoordinate:location]; 
     [self.mapView addAnnotation:newAnnotation]; 
     [newAnnotation release]; 

    } 

在dayURL日誌旁邊,我得到CFStringRef無效。

請幫助...!

+0

你的clubNum是什麼類型? – iTukker

+0

查詢dayURL是否有價值? –

+0

這是一個NSString。 –

回答

2

這條線:

NSString *latitudeURL = [[NSString alloc] initWithFormat:@"%@PartyCentral/WeeklyParties/Club%@/Location/latitude.txt"]; 

包含一個格式化字符串沒有提供的參數,其是將具有解引用的任何值都在堆棧上的效果。如果那些指針不是有效內存,則會發生此類錯誤。

相關問題