I was preparing for a customCellView in a tableView. According to me, everything was perfect in .xib and methods. I am getting an exception in configuring the cell.
int listIndex = [indexPath indexAtPosition:[indexPath length] - 1];
NSLog(#"outside");
cell.lblName.text = (NSString *) [[directoryContent objectAtIndex:listIndex] objectForKey:#"filesName"];
cell.lblSize.text = (NSString *) [[directoryContent objectAtIndex:listIndex] objectForKey:#"filesSize"];
cell.lblType.text = (NSString *) [[directoryContent objectAtIndex:listIndex] objectForKey:#"filesType"];
return cell;
The compiler works till the NSLog(#"outside");. But it does not proceeds to the next line. I am terminated by the error
2010-11-15 20:32:28.623 iDataTraveller[5346:207] outside
2010-11-15 20:32:28.625 iDataTraveller[5346:207] -[NSPathStore2 objectForKey:]: unrecognized selector sent to instance 0x5f19cf0
2010-11-15 20:32:28.627 iDataTraveller[5346:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSPathStore2 objectForKey:]: unrecognized selector sent to instance 0x5f19cf0'
Please help me to proceed.. Thank you in advance..
Wherever you created directoryContent, you stored the wrong object in it.
NSPathStore2 is an object that will be created if you use something like stringByAppendingPathComponent: on a NSString.
I guess you just stored the filename in the array but wanted to store a NSDictionary created from NSFileManagers attributesOfItemAtPath:error:
Check that part were you add objects to directoryContent again.
This is my code. Have a look at this. Let me know what i am lagging.
- (void)listFiles {
NSFileManager *fm =[NSFileManager defaultManager];
NSError *error = nil;
NSString *parentDirectory = #"/Users/akilan/Documents";
NSArray *paths = [fm contentsOfDirectoryAtPath:parentDirectory error:&error];
if (error) {
NSLog(#"%#", [error localizedDescription]);
error = nil;
}
NSMutableArray *array = [[NSMutableArray alloc] init];
self.directoryContent = array;
[array release];
for (NSString *path in paths){
filesName = [[path lastPathComponent] stringByDeletingPathExtension];
filesPath = [parentDirectory stringByAppendingPathComponent:path];
filesDirectory = [NSMutableDictionary dictionaryWithDictionary:[[NSFileManager defaultManager] attributesOfItemAtPath:filesPath error:nil]];
filesSize = [filesDirectory objectForKey:NSFileSize];
filesType = [path pathExtension];
createdDate = [filesDirectory objectForKey:NSFileCreationDate];
modifiedDate = [filesDirectory objectForKey:NSFileModificationDate];
filesDirectory = [NSDictionary dictionaryWithObjectsAndKeys:filesPath,#"filesPath",
filesName,#"filesName",filesSize, #"filesSize", filesType, #"filesType",
createdDate,#"createdDate", modifiedDate,#"modifiedDate", nil];
NSLog(#"%#", filesDirectory);
}
}
Thanks..
You have not retained directoryContent.
Can you show the code where directoryContent is created?
You can tell this because your error message says NSPathStore2 when it should be trying to call objectforKey on NSDictionary - this means that the memory where your dictionary was is not being used by something else :)
Related
I have problem with my Iphone project in viewDidLoad event the app crash on
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
I am trying to store information from text Filed can someone help me to solve the problem
- (void)viewDidLoad{
NSString *filePath = [self dataFilePath];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
for (int i = 0; i < 2; i++) {
UITextField *theField = self.lineFields[i];
theField.text = array[i];
}
NSData *data = [[NSMutableData alloc]
initWithContentsOfFile:filePath];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc]
initForReadingWithData:data];
BIDThreeLines *threelines = [unarchiver decodeObjectForKey:kRootKey];
[unarchiver finishDecoding];
for (int i = 0; i < 2; i++) {
UITextField *theField = self.lineFields[i];
theField.text = threelines.lines[i];
}
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification
object:app];
}
Error
2013-03-25 23:29:45.592 MobilePaymentsApp[1182:c07] -[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x8d0e8d0
2013-03-25 23:29:45.593 MobilePaymentsApp[1182:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x8d0e8d0'
*** First throw call stack:
(0x1c96012 0x10d3e7e 0x1d214bd 0x1c85bbc 0x1c8594e 0x1c0ae18 0xb030e8 0x339c 0xf91c7 0xf9232 0x483d5 0x4876f 0x48905 0x51917 0x2cc5 0x15157 0x15747 0x1694b 0x27cb5 0x28beb 0x1a698 0x1bf1df9 0x1bf1ad0 0x1c0bbf5 0x1c0b962 0x1c3cbb6 0x1c3bf44 0x1c3be1b 0x1617a 0x17ffc 0x29fd 0x2925)
libc++abi.dylib: terminate called throwing an exception
(lldb)
https://github.com/a-elnajjar/MobilePaymentsApp
NSKeyedArchiver returns object that you have stored in it. eg. if you have stored an array then it will return an array. so be careful while unarchiveing objects.
in following example i have read an array from NSKeyedUnarchiver.
NSData *data = [[NSMutableData alloc] initWithContentsOfFile:filePath];
NSArray *arr = [NSKeyedUnarchiver unarchiveObjectWithData:data];
Look in the crash log's stack trace to see where exactly this call is
happening.
If the variable you're sending -row to isn't actually typed as an
NSArray, it's likely that you've failed to follow the memory
management rules for that variable. These same symptoms are very
commonly caused by that. Something that responds to -row could have
existed at one point, been deallocated because you didn't -retain it,
and then an NSArray was later allocated in that spot.
Run a "Build & Analyze," and re-re-review the memory management
guidelines until you know them in your sleep.
Source: [NSCFArray row]: unrecognized selector sent to instance 0x3953a20
I am parsing JSON data with JSONKit as NSMutableDictionary.
NSString *str = [[NSString alloc] initWithData:self.responseData encoding:NSUTF8StringEncoding];
NSMutableDictionary *jsonResponse = [self.responseData objectFromJSONData];
NSMutableDictionary *newData = [[NSMutableDictionary alloc] init];
[newData addEntriesFromDictionary:[jsonResponse mutableCopy]];
When i do this i am getting this error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableDictionary addEntriesFromDictionary:]: dictionary argument is not an NSDictionary'
I am trying to figure out what is causing this problem. I know that jsonResponse is an object of JKArray from my other experience.
I need help.
Thanks.
Try the following:
id object = [self.responseData objectFromJSONData];
NSLog(#"%#", [object class]);
Most likely your response is an array instead of a dictionary.
If you really want to convert the array into a dictionary, you could do something like this, using a self-defined key:
NSArray *array = [self.responseData objectFromJSONData];
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObject:array forKey:#"posts"];
Though perhaps there are some better options if you could show me the contents of your array.
-(void)saveDictionary:(int)counter
{
NSString *path=[[NSBundle mainBundle] pathForResource:#"Data" ofType:#"plist"];
NSString *test = [NSString stringWithFormat:#"%d", counter];
[theDictionary setObject:test forKey:#"Counter"]; <---- Error
[theDictionary writeToFile:path atomically:YES];
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self saveDictionary:[_viewController counter]];
}
Error:
-[NSCFString setObject:forKey:]: unrecognized selector sent to instance
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString setObject:forKey:]: unrecognized selector sent to instance
I can Load the value for Key "Counter" from plist.
If I want to save the new value for same key "Counter" ... Error.
Need Help, spent hours.
bye
Here is the Code to initialize theDictionary:
-(void)initDictionary {
if (theDictionary == nil) {
NSString *path=[[NSBundle mainBundle] pathForResource:#"Data" ofType:#"plist"];
theDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
theString = [theDictionary objectForKey:#"Counter"];
}
}
Found it!
theString = [[NSString alloc] initWithFormat:[theDictionary objectForKey:#"Counter"]];
Thanks All!
This is because the object stored in theDictionary is actually an NSString and NSString doesn't contain a method called -setObject:forKey. Check your code for any places where theDictionary is being assigned and be sure that is actually an NSMutableDictionary.
check the initilization .. you could have done it like this .
NSMutableDictionary *dictoForSyncing = [[NSMutableArray alloc] init];
Sounds like theDictionary is a string instead of an NSMutableDictionary. Where is it created and what happended to it in the meantime?
This says that 'theDictionary' is not a dictionary at all. Most likely it was released earlier and some NSString has taken its place.
Are you using ARC? Where was 'theDictionary' defined.
And have you tried the zombies Instrument to track this down? That should help.
It seems that your property theDictionary isn't actually a dictionary, but a string (NSString). Where is theDictionary defined?
NSMutableArray *myObjFromFile = ....;
NSMutableDictionary *tmpDictFromFile =
[[[myObjFromFile objectAtIndex:xx] mutableCopy]; mutableCopy];
[tmpDictFromFile setObject:"YOUR OBJECT"
forKey:"YOUR KEY"];
i am getting json data from this link
now i want data from "html_instructions": part
NSDictionary *result = [stringtext JSONValue];
NSLog(#"here");
NSArray *resultarr = [result objectForKey:#"routes"];
NSString *string;
for(NSDictionary *di in resultarr){
NSLog(#"for loop");
string = [[di objectForKey:#"legs"] objectForKey:#"steps"];
}
but after printing "for loop" in console it is throwing an exception
2011-05-20 16:16:26.997 speedymap[759:207] -[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x62a7d60
2011-05-20 16:16:26.999 speedymap[759:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x62a7d60'
please help me
i want html_instructiuons field value
Check if resultarr and di really contains anything or not.
NSDictionary *result = [stringtext JSONValue];
NSLog(#"here");
NSArray *resultarr = [result objectForKey:#"routes"];
CFShow(resultarr);
NSString *string;
for(NSDictionary *di in resultarr){
CFShow(di);
NSLog(#"for loop");
NSArray *tempArr = [[di objectForKey:#"legs"] objectForKey:#"steps"];
}
http://jsonviewer.stack.hu/#http://maps.googleapis.com/maps/api/directions/json?origin=delhi&destination=noida&waypoints=&sensor=true
Check the viewer and set the values accordingly. [di objectForKey:#"legs"] returns an array. the first object of that array is a dictionary which has the key steps. But that too returns another array.
it seems my Problem isn't a problem for anybody eles because I havend fount anything about it.
so it maybe isn't such a big Problem but for me it is.
I have this MutableArray filled with alot of data from an XML file.
-Name -Age -Address
The search goes for the Name, and the filtering works pretty fine so far.
what I do is search the array with rangeOfString but that only returns the String (-Name) and not the Array with it's content like the original Array because its only a string now.
can anyone tell me how do I accomplish this
That's my search so far
if ([[self searcher] length] != 0)
{
for (NSString *currentString in [self listOfContent])
{
if ([currentString rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound)
{
[[self filteredListOfContent] addObject:currentString];
}
searcher is the String in the SearchBar.
or is there any other more efficent way or is it possible to search for any value in the MutipleArry?!?
Any Ideas and suggestions are welcome
I changed the code to this
NSString *searchText = searchBar.text;
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (NSDictionary *dictionary in listOfContent)
{
//NSArray *array = [dictionary objectForKey:LNAME];
[searchArray addObject:dictionary];
}
for (NSString *sTemp in searchArray)
{
NSLog(#"array %#", searchArray);
if ([sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch].location != NSNotFound)
[filteredListOfContent addObject:searchArray];
}
the log shows that the filter seems to work but then I get this error
2010-10-22 16:18:09.708 TableView[6114:207] -[__NSCFDictionary rangeOfString:options:]: unrecognized selector sent to instance 0x5c3f540
2010-10-22 16:18:09.712 TableView[6114:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary rangeOfString:options:]: unrecognized selector sent to instance 0x5c3f540'
can anyone tell me what the problem is
And Still no solution found I changed the Code to this:
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (NSDictionary *dictionary in contentsList)
{
NSArray *array = [dictionary allValues];
[searchArray addObjectsFromArray:array];
}
for (NSDictionary *dict in searchArray)
{
if ([[dict valueForKey:#"NAME"] rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound) {
NSLog(#"Filter %#", dict);
[searchResults addObject:dict];
}
now i Have the array with the values but still get the error
2010-10-28 16:23:46.124 TableViews[8373:207] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance 0x5a5eb00'
can anyone explain me waht taht that error means or waht I did wrong?!?
2010-10-28 16:23:46.124 TableViews[8373:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance 0x5a5eb00'
That error means you treated an NSString as if it were an NSDictionary by sending the message -objectForKey: to it.