App Crashing when Caption isn't there [closed] - ios

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
My app displays the Caption of the Instagram Picture and crashes every time there isn't a caption. How would I prevent that from happening? Here is the code that I am using:
if (entry[#"caption"][#"text"]) {
NSString *caption = entry[#"caption"][#"text"];
UILabel *instagramCaptionLabel = (UILabel *)[cell viewWithTag:103];
[instagramCaptionLabel setFont:[UIFont fontWithName:#"Helvetica-Light" size:12.0]];
[instagramCaptionLabel setText:caption];
}
Here is the error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull objectForKeyedSubscript:]: unrecognized selector sent to instance 0x1ed8068'

Based on the error message this means you do have a value for #"caption" but it happens to be an NSNull object.
You have two choices:
1) Don't put NSNull values in the dictionary.
or
2) Update your if statement:
if (entry[#"caption"] != [NSNull null] && entry[#"caption"][#"text"] != [NSNull null])

Related

iOS App error and its causing the app to crash [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I got this error while running my app for test:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(0x30d48fd3 0x3b5c1ccf 0x30c82a8b 0x30c8c391 0x1038ab 0x335d45a7 0x335d3efb 0x335ce58b 0x3356a709 0x33569871 0x335cdcc9 0x35bd6aed 0x35bd66d7 0x30d13ab7 0x30d13a53 0x30d12227 0x30c7cf0f 0x30c7ccf3 0x335ccef1 0x335c816d 0x1053c1 0x3baceab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
Causing the app to crash
Without more context, it'll be tough to give a good answer. That said, inserting a nil object into an NSArray-type class (including NSMutableArray) will cause an e exception to be thrown. If you need an "empty" value in an array, use [NSNull null].
To debug this, try enabling an exception breakpoint in Xcode. Here's how:
On the lefthand panel, choose the second icon from the right. That's the breakpoints panel.
On the bottom corner, there's a little plus. Click it.
In the menu, choose "Add Exception Breakpoint"
Run your code. When it crashes, it'll show you the line that's crashing, as well as a stack trace.
You are trying to insert a nil object. If you want to add nill object you should add as following. You can't add it directly
[array addObject:[NSNull null]];
You can't add nil to an array (as it holds pointers to the objects) so it crashes. If you need to store nil in an NSArray use NSNull which simply wraps nil into an array.

Ios Add objects in a NSMutableArray [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
how can I add an object in an array by clicking a button
I use this methode :
- (void)insertNewObject:(id)sender
{
[orderListe addObject:[[DataOrder alloc]initWithName:#"Michael" price:18 taille:#"junior" supplement:#"boeuf"]];
}
When I do that my application crash and say :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DataOrder initWithName:]: unrecognized selector sent to instance 0x8aa4fa0'
What can i do to simply add an object to an array ?
Thank you
The error your getting has to do with the DataOrder object. During it's initialization it ran into an error. You're sending it some value it isn't expecting.
Perhaps try and separate the line where you alloc the Data Order object and try to add it to the array?
DataOrder *do = [[DataOrder alloc] initWithName....];
[orderListe addObject: do];
this will let you see where you messed up?
Of course that you can add an object to an array. The exception is thrown because the method initWithName:price: ... is not implemented in the DataOrder class.

Parse Quickstart error [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm new to Objective-C and to programming to be honest. Working on a bit of a project and have had the following returned when I try and use the Parse quickstart. Any suggestions?
2013-08-21 21:47:41.388 ParseStarterProject[3284:c07] * Terminating
app due to uncaught exception 'NSInvalidArgumentException', reason:
'cannot setReadAccess for unsaved user'
* First throw call stack: (0x21f4012 0x1d27e7e 0x21f3deb 0x35057 0x3555d 0xaa33 0x32a5 0x2f76 0x3332 0xac5c 0x2e00 0xf761c7 0xf76232
0xec53d5 0xec5cc1 0x2636 0xe92157 0xe92747 0xe9394b 0xea4cb5 0xea5beb
0xe97698 0x214fdf9 0x214fad0 0x2169bf5 0x2169962 0x219abb6 0x2199f44
0x2199e1b 0xe9317a 0xe94ffc 0x2495 0x2395) libc++abi.dylib: terminate
called throwing an exception (lldb)
The Parse SDK is throwing an exception. From the error message, it looks like the problem is that you're sending -setReadAccess for an unsaved user. That makes sense -- it'd probably be difficult to read from an user object that hasn't yet been saved.

data not coming for nsmutablearray [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have NSMutableArray data as below.
{
Id = "57\n ";
Image = "http://www.mysite.com/32f7aff4-9cb2-4044-a555-bfac8ea6eace.gif\n ";
NameEn = "salim\n ";
SpecializationsEn = "Dentistry\n ";
}
Now I wanted to get Imaage name hence I tried
[[feeds objectAtIndex:0] objectForKey:#"Image"]
but this is giving me error as
-[__NSDictionaryI objectAtIndex:]: unrecognized selector sent to instance 0x759b0b0
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI objectAtIndex:]: unrecognized selector sent to instance 0x759b0b0'
Any idea what is going wrong?
As far as I can tell from the data structure that you've posted, you don't have an array object but rather a dictionary object and a dictionary won't respond to objectAtIndex:.
Try replacing this:
[[feeds objectAtIndex:0] objectForKey:#"Image"]
With this:
[feeds objectForKey:#"Image"]
Or, if you prefer modern Objective-C syntax, this:
feeds[#"image"];
If you use NSMutableArray, then you should write[array valueForKey:#"key"];to retrieve elements from it

NSDictionary dictionaryWithObject:key: crashes app [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
NSObject * obj = [[NSObject alloc] init];
NSDictionary * dict = [NSDictionary dictionaryWithObject:obj forKey:#"test"];
For some reason gives me the following crash when executed :
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: '-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable
object'
I can't pinpoint what the issue is as I've done my homework and it seems to be valid code... I'm breaking my head over this!
I just ran your code without any problems. Are you sure it's not crashing after creating the dictionary? The exception you're getting seems to indicate that you're trying to add an object to the dictionary, which can't be done since NSDictionary is immutable. You need to use NSMutableDictionary if you want to add/remove objects after creation.

Resources