tags:

views:

494

answers:

3
A: 

The object at 0x3814530 is a NSString and yet you treat it as a NSDictionary, and you get a runtime exception.

This article describes breaking on exceptions. Use the debugger to inspect the code that is adjacent to your exception.

diciu
can you elaborate how to do that? thanks.. im new to this game.
Sam Jarman
+1  A: 

Hi Sam,

The error message is a bit cryptic, but it basically says that you tried to send the message "objectForKey:" to an object of class "NSString", and that method doesn't exist in the NSString class. It sounds like you're programatically grabbing an object and expecting that object to be an NSDictionary. At runtime, your NSDictionary * is actually being set to an NSString *, and you don't get an exception until that object is actually used incorrectly.

The fact that you can say "give me this object of unknown type, assume it's a dictionary, and call this function" is actually pretty cool once you get comfortable with Objective-C, but it's hell to get used to. I've always found that Objective-C assumes you know what you're doing. Some people love it because it lets them write clean, concise code -- but it raises the learning curve quite a bit.

Feel free to post a code snippet if you need more help tracking this one down!

  • Ben

UPDATE:

It looks like when you setup your data in viewDidLoad:, you are loading a bunch of arrays from separate files. Then you add the contents of those arrays to your main data array like this:

[listOfItems addObjectsFromArray:arrayStructuresF];

I think those lines shouldn't be there. Further down, you're creating dictionaries for each letter and then adding those to the listOfItems. At the end of the function, listOfItems contains a whole bunch of string items AND a whole bunch of dictionaries. The string items come first, so you're getting NSStrings when you expect NSDictionaries.

P.S. You might want to condense some of this into loops once it's all working. You could create an array of the letters A,B,C,D, etc... and then load all the files in a loop using filenames made using NSString's stringWithFormat:. Just a thought!

Ben Gotow
im gonna shove up the whole .m file.. where im sure something is wrong. Thanks for the response though Ben.
Sam Jarman
RE:Update what im wanting, is an array, with dictionaries in it. and those dictionaries to have an array of things starting with that letter. so for 'A', an array with all the @"A-"'s in it, and then a dictionary storing that. as it is my understanding that you cant put objects into a NSDict instance.. only arrays? could you show me an example perhaps? i was roughly following this http://www.iphonesdkarticles.com/2009/01/uitableview-sectioned-table-view.html when i started.
Sam Jarman
wholy crap. good man Ben!. i just deleted the block of [listOfItems addObjectsFromArray:arrayStructuresF];and.. now it launches perfectly and works perfectly.
Sam Jarman
A: 

Try turning on NSZombiesEnabled.

  1. Double-click your executable in the Executable group of your project.
  2. Click the Arguments tab.
  3. In the "Variables to be set in the environment:" section, create a new variable called NSZombieEnabled and set it to YES.

I'm betting you'll find you're sending a message to an object that's already been released to the point that it's been deallocated.

Steven Fisher
how do i do that?
Sam Jarman
I meant to expand that answer when I had more time, but either I forgot or I never had any time! Done now, thanks. :)
Steven Fisher