Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-17-2009, 10:45 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 24
Default Searching crash

I got my search function to search one array, while displaying titles from another and keeping pairs of information together. I would now like to expand it from pairs to threes, and possibly fours. Unfortunately, as soon as I added objects into a third array (without changing the search-related coding at all), the simulator thres an uncaught exception error and crash. The arrays are NSMutableArrays, and they each contain 120 strings. I don't understand why it would crash a good program when all I did was add objects to the array. Any suggestions?
mazraf is offline   Reply With Quote
Old 08-17-2009, 10:48 AM   #2 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,557
Send a message via ICQ to smithdale87 Send a message via AIM to smithdale87 Send a message via Skype™ to smithdale87
Default

Quote:
Any suggestions?
Post the code where you're adding the objects. Also post the exception that you're getting.
smithdale87 is online now   Reply With Quote
Old 08-17-2009, 11:02 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 24
Default

Code:
- (void)viewDidLoad {
    [super viewDidLoad];

	// Initialize the source arrays
	TdataSource = [[NSMutableArray alloc]init];
	RdataSource = [[NSMutableArray alloc]init];
	BdataSource = [[NSMutableArray alloc]init];
	IdataSource = [[NSMutableArray alloc]init];

	[TdataSource addObject:@""];
// x120
	[RdataSource addObject:@""];
// x120
	[BdataSource addObject:@""];
// x120
	[IdataSource addObject:@""];
// x120

	//initialize the other arrays;
	TtableData =	[[NSMutableArray alloc]init];
	RtableData =	[[NSMutableArray alloc]init];
	BtableData =	[[NSMutableArray alloc]init];
	ItableData =	[[NSMutableArray alloc]init];
}
Code:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

	// remove all data that belongs to the previous search
	[TtableData removeAllObjects];
	[RtableData removeAllObjects];
	
	if([searchText isEqualToString:@""] || searchText==nil) {
		[myTableView reloadData];
		return;
	}
	
	NSString *searchLower = [searchText lowercaseString];
	
	NSInteger counter = 0;
	
	for(NSString *name in RdataSource) {
		NSString *nameLower = [name lowercaseString];
		NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
		NSRange r = [nameLower rangeOfString:searchLower];
		
		if(r.location != NSNotFound) {
			[RtableData addObject:name];
			[TtableData addObject:[TdataSource objectAtIndex:counter]];
		}
		
		counter++;
		[pool release];
	}
	
	[myTableView reloadData];
}

I'm actually unsure what the exception is. The simulator goes behind xcode, and I get a message under 'Build and Go' at the top that says '___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___'
It is thrown as soon as you try to enter text in the search field. It only happens after I uncomment a block of 120 addObjects. 2 is good, 3 crashes, and I haven't tried with 4.
mazraf is offline   Reply With Quote
Old 08-17-2009, 11:04 AM   #4 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,557
Send a message via ICQ to smithdale87 Send a message via AIM to smithdale87 Send a message via Skype™ to smithdale87
Default

when you get the exception, open up the console, type "bt".. this should give you exactly what line in your code is crashing
smithdale87 is online now   Reply With Quote
Old 08-18-2009, 02:12 AM   #5 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 24
Default

Code:
(gdb) bt
#0  0x302ac924 in ___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___ ()
#1  0x963f2e3b in objc_exception_throw ()
#2  0x3028e5fb in +[NSException raise:format:arguments:] ()
#3  0x3028e55a in +[NSException raise:format:] ()
#4  0x305684e9 in _NSArrayRaiseBoundException ()
#5  0x30505a47 in -[NSCFArray objectAtIndex:] ()
#6  0x00007a74 in -[SearchViewController searchBar:textDidChange:] (self=0xd59ac0, _cmd=0x319f5a4a, searchBar=0xd5d670, searchText=0xd6e9e0) at /Users/krv/Desktop/MobilePearls/Classes/SearchViewController.m:635
#7  0x30ac2a9c in -[UISearchBar(UISearchBarStatic) _searchFieldEditingChanged] ()
#8  0x309596b1 in -[UIControl(Deprecated) sendAction:toTarget:forEvent:] ()
#9  0x3095bcd9 in -[UIControl(Internal) _sendActionsForEventMask:withEvent:] ()
#10 0x30960dc2 in -[UITextField fieldEditorDidChange:] ()
#11 0x3096f177 in -[UIFieldEditor webViewDidChange:] ()
#12 0x30509e5a in _nsnote_callback ()
#13 0x302389e5 in _CFXNotificationPostNotification ()
#14 0x30507710 in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
#15 0x3024a10d in __invoking___ ()
#16 0x30249ff8 in -[NSInvocation invoke] ()
#17 0x358763a7 in SendDelegateMessage ()
#18 0x332dcebf in WebEditorClient::respondToChangedContents ()
#19 0x358e7f22 in WebCore::Editor::respondToChangedContents ()
#20 0x358e681c in WebCore::Editor::appliedEditing ()
#21 0x358e66b3 in WebCore::TypingCommand::typingAddedToOpenCommand ()
#22 0x358d689f in WebCore::TypingCommand::insertTextRunWithoutNewlines ()
#23 0x358d67db in WebCore::TypingCommand::insertText ()
#24 0x358d6623 in WebCore::TypingCommand::doApply ()
#25 0x358d6348 in WebCore::EditCommand::apply ()
#26 0x358d5695 in WebCore::TypingCommand::insertText ()
#27 0x358d4b9c in WebCore::Editor::insertTextWithoutSendingTextEvent ()
#28 0x358d47d5 in WebCore::EventHandler::defaultTextInputEventHandler ()
#29 0x358a39d6 in WebCore::EventTargetNode::defaultEventHandler ()
#30 0x358a3660 in WebCore::EventTargetNode::dispatchGenericEvent ()
#31 0x358a3101 in WebCore::EventTargetNode::dispatchEvent ()
#32 0x358d4467 in WebCore::EventHandler::handleTextInputEvent ()
#33 0x358d4369 in WebCore::Editor::insertText ()
#34 0x332dc83d in -[WebHTMLView(WebNSTextInputSupport) insertText:] ()
#35 0x358d41f4 in -[WAKResponder tryToPerform:with:] ()
#36 0x332dc323 in -[WebView(WebViewEditingActions) _performResponderOperation:with:] ()
#37 0x332dc280 in -[WebView(WebViewEditingActions) insertText:] ()
#38 0x30a50c05 in -[UIWebDocumentView insertText:] ()
#39 0x30a1c1b6 in -[UIKeyboardImpl addInputString:fromVariantKey:] ()
#40 0x30b18d61 in -[UIKeyboardLayoutStar sendStringAction:forKey:] ()
#41 0x30b17736 in -[UIKeyboardLayoutStar handleHardwareKeyDownFromSimulator:] ()
#42 0x308fff85 in -[UIApplication handleEvent:withNewEvent:] ()
#43 0x308fad82 in -[UIApplication sendEvent:] ()
#44 0x309013e1 in _UIApplicationHandleEvent ()
#45 0x32046375 in PurpleEventCallback ()
#46 0x30245560 in CFRunLoopRunSpecific ()
#47 0x30244628 in CFRunLoopRunInMode ()
#48 0x32044c31 in GSEventRunModal ()
#49 0x32044cf6 in GSEventRun ()
#50 0x309021ee in UIApplicationMain ()
#51 0x00001dc0 in main (argc=1, argv=0xbfffef7c) at /Users/krv/Desktop/MobilePearls/main.m:14
(gdb)
So, the problem is with my 'main.m' at line 14?

Code:
int main(int argc, char *argv[]) {
    
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}
That's the code from my main. Line 14 is the int retval line, I think.
mazraf is offline   Reply With Quote
Old 08-18-2009, 03:30 AM   #6 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 24
Default

Fixed it. I got the name of one set of arrays wrong. They all had to be the same size, but they weren't.
mazraf is offline   Reply With Quote
Reply

Bookmarks

Tags
array, crash, exception, search, strings

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 251
24 members and 227 guests
@sandris, ADY, Dani77, diyora, FAED, fredidf, F_Bryant, GHuebner, HDshot, iDifferent, JasonR, mer10, Oral B, prchn4christ, Rudy, smithdale87, Speed, spiderguy84, stekki, tgjorgoski, Thompson22, Touchmint, twerner, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,752
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:03 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0