What does internalconsistency mean? - objective-c

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/C8CF9D6E-4B29-416B-8973-A6F18C0CE691/.app> (loaded)' with name 'BGCinemaScheduleCell''
*** First throw call stack:
(0x32d812a3 0x3aa2697f 0x32d811c5 0x34d26571 0x34d2e2b7 0x137e4d 0x13833f 0x1383fd 0x1b6b97 0x34dffdef 0x17218b 0x34bd454d 0x34bb9313 0x34bd07cf 0x34b8c803 0x34936d8b 0x34936929 0x3493785d 0x34937243 0x34937051 0x34936eb1 0x32d566cd 0x32d549c1 0x32d54d17 0x32cc7ebd 0x32cc7d49 0x3688b2eb 0x34bdd301 0xa1385 0x3ae5db20)
libc++abi.dylib: terminate called throwing an exception
Okay there is indeed an actual XIB named BGCinemaScheduleCell
I got this error here:
-(void) vLoadMainBundle
{
if ([self class] == [BGBaseTableViewCell class])
{
return;
}
NSString * className = NSStringFromClass([self class]);
[[NSBundle mainBundle] loadNibNamed:className owner:self options:nil];
}
I have no idea what NSInternalInconsistencyException mean. the value of className is loadNibNamed

It turns out the xib hasn't been copied to the bundle resources that an answer in https://stackoverflow.com/a/5646337/2027232 would work.
The next question would be why the xib isn't copied to the bundle resources when I created it.

Related

iOS App NSInvalidArgumentException

I have been trying to work through a bug for many hours in my iOS App involving rangeOfString and have finally been able to track down where my app crashes. My app sets TextViewA to the first half of my MainTextView. What if statement should be added should be added to check for nil?
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSCFString rangeOfString:options:range:locale:]: nil argument'
*** First throw call stack:
.
[[myViewController tvTextFirstHalf] setText:[[mainTextView.text componentsSeparatedByString:[[myViewController tvTextMiddle]text]] objectAtIndex:0]];
..............................................................................................
No memory available to program now: unsafe to call malloc
2013-01-04 14:30:58.138 Type[7279:c07] separator: (null)
2013-01-04 14:30:58.138 Type[7279:c07] mainTextView: ; layer = ; contentOffset: {0, 0}
>
2013-01-04 14:30:58.139 Type[7279:c07] mainTextView.text: TESTTTTTTTT f f.
2013-01-04 14:30:58.142 Type[7279:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSCFString rangeOfString:options:range:locale:]: nil argument'
* First throw call stack:
(0x1a5d012 0x1882e7e 0x1a5cdeb 0xf78688 0xf87d88 0xfd05df 0x165ec 0x15dc6 0x1fd7b 0x56d8d5 0x56db3d 0xf74e83 0x1a1c376 0x1a1be06 0x1a03a82 0x1a02f44 0x1a02e1b 0x221d7e3 0x221d668 0x4be65c 0x2c5d 0x2b85)
libc++abi.dylib: terminate called throwing an exception
(gdb)
This oneliners are not considered a good practice in obj-C (i know, it's arguable).
Try to break:
[[myViewController tvTextFirstHalf] setText:[[mainTextView.text componentsSeparatedByString:[[myViewController tvTextMiddle]text]] objectAtIndex:0]];
Into some more debugging-friendly code:
NSString *separator = [[myViewController tvTextMiddle]text];
NSLog (#"separator: %#", separator);
NSLog (#"mainTextView: %#",mainTextView); //is this one nil?
NSLog (#"myViewController.tvTextMiddle: %#", myViewController.tvTextMiddle); //what about this one??
NSLog (#"mainTextView.text: %#",mainTextView.text);
NSArray *components = [mainTextView.text componentsSeparatedByString:separator];
NSLog (#"we found %d components", components.count);
NSString *result = (NSString *)[components objectAtIndex:0];
NSLog (#"result should be: %#", result);
[[myViewController tvTextFirstHalf] setText:result];
The code will break ofcourse but at least you'll know where the problem lies.
You could change last four lines then in something like:
if (components.count >= 1)
{
NSString *result = (NSString *)[components objectAtIndex:0];
NSLog (#"result should be: %#", result);
[[myViewController tvTextFirstHalf] setText:result];
}
else
{
[[myViewController tvTextFirstHalf] setText:#"empty!"];
}
EDIT:
From the NSLog you posted it is obvious that your separator [[myViewController tvTextMiddle]text] is null. Note that null is not the same as empty string. It is unallocated string.
My guess is that actually your tvTextMiddle is null (or if you are using XIB files it is not properly connected to the IBOutlet).
You can check that by adding (somewhere before the breaking-line):
NSLog (#"myViewController.tvTextMiddle: %#", myViewController.tvTextMiddle);
The crash is due to this call componentsSeparatedByString.
If your textview is nil or no text then crash'll occur.
So add a condition like:
if(mainTextView.text.length != 0 && [myViewController tvTextMiddle]text].length != 0)
{
[[myViewController tvTextFirstHalf] setText:[[mainTextView.text componentsSeparatedByString:[[myViewController tvTextMiddle]text]] objectAtIndex:0]];
}

Problems passing data between different classes with a method

I have this in a class:
NSString *globalMidiData = #"30a0a00\n";
switch (IndicatorCheckNXT) {
case 1:
[testRobot checkTestRobot:globalMidiData];
break;
default:
break;
}
And in another class I have this:
-(void) checkTestRobot: (NSString *)midiDataGlobal{
bool pressed;
bool pressed2;
NSString *miawmiaw =[NSString alloc];
miawmiaw=midiDataGlobal;
}
And I got this message:
-[AppDelegate checkTestRobot:]: unrecognized selector sent to instance 0x18acb0
2012-11-23 20:45:31.755 Exemple1[477:707] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppDelegate checkTestRobot:]: unrecognized selector sent to instance 0x18acb0'
What I am doing wrong?
Obviously you send checkTestRobot to the wrong object. testRobot seems to point to the AppDelegate and not to an instance of your class.
Also you should replace this:
NSString *miawmiaw =[NSString alloc];
miawmiaw=midiDataGlobal;
with:
NSString *miawmiaw = [midiDataGlobal copy];

trouble debugging during runtime

I have written a some code for a drill down table app I have been making, but the app crashes only during runtime. Xcode doesn't give me any errors while building the app. The debugger outputs:
2012-10-18 10:58:26.513 second[474:c07] -[NavController setItems:]: unrecognized selector >sent to instance 0xc217a00
2012-10-18 10:58:26.515 second[474:c07] * Terminating app due to uncaught exception >'NSInvalidArgumentException', reason: '-[NavController setItems:]: unrecognized selector sent >to instance 0xc217a00'
* First throw call stack:
(0x14b8022 0xeb8cd6 0x14b9cbd 0x141eed0 0x141ecb2 0x3fbe 0xe2a1e 0x41401 0x41670 0x41836 >0xbfc9dd8 0x4872a 0x19596 0x1a274 0x29183 0x29c38 0x1d634 0x13a2ef5 0x148c195 0x13f0ff2 >0x13ef8da 0x13eed84 0x13eec9b 0x19c65 0x1b626 0x1d40 0x1cd9)
terminate called throwing an exception
I think I understand that the error lies in NavController.m where:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString* path = [[NSBundle mainBundle] pathForResource:#"Data" ofType:#"plist"];
MasterViewController* root = (MasterViewController*)self.topViewController;
NSDictionary* thelist = [NSDictionary dictionaryWithContentsOfFile:path];
root.items = [thelist objectForKey:#"Items"];
root.navigationItem.title = [thelist objectForKey:#"name"];
}
btw, I made the array items like this: (nonatomic, retain) NSArray* items;
The app crashes, because of the following line:
root.items = [thelist objectForKey:#"Items"];
This line is just a shortcut for writing:
[root setItems:[thelist objectForKey:#"Items"]];
And the runtime complains that there is no method setItems: found. The reason why there is compile error is because you tell the compiler that root is of class MasterViewController, however, that is not true. At runtime the obj-c runtime finds out that root is in fact of class NavController and it seems like NavController has no setItems: method.
In other words, this line is wrong:
MasterViewController* root = (MasterViewController*)self.topViewController;
You lie about the class; self.topViewController returns an object that is of class NavController, yet you force the compiler to treat it as MasterViewController which will fail as soon as you call a method that is not found for NavController.
The problem is probably here:
MasterViewController* root = (MasterViewController*)self.topViewController;
self.topViewController is proably not an instance of MasterViewController, but a NavController instance and there you go.

Playing video on IOS

I have downloaded the source files from
http://mobile.tutsplus.com/tutorials/iphone/mediaplayer-framework_mpmovieplayercontroller_ios4/
and the app works perfectly, but when I try to swap out my own video by changing the following code:
pathForResource:#"big-buck-bunny-clip" ofType:#"m4v"
to
pathForResource:#"example" ofType:#"mp4"
the app crashes when I try to play the video and I receive a message in the output saying:
"2012-09-13 20:32:59.106 BigBuckBunny[1081:11f03] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[NSURL initFileURLWithPath:]: nil string parameter'
** First throw call stack:
(0x1722022 0x10f6cd6 0x16caa48 0x16ca9b9 0x4e53b 0x4e4c5 0x2da4 0x1723e99 0x36d14e 0x36d0e6 0x413ade 0x413fa7 0x413266 0x3923c0 0x3925e6 0x378dc4 0x36c634 0x1e1aef5 0x16f6195 0x165aff2 0x16598da 0x1658d84 0x1658c9b 0x1e197d8 0x1e1988a 0x36a626 0x297d 0x28f5)
terminate called throwing an exception(lldb) "
I have my new video file inside the folder with the original big-buck-bunny-clip.m4v file, and I put it in the project.
What am I doing wrong and how do I fix this?
I managed to play my own video by going to the file within Xcode and checking the box next to BigBuckBunny under Target Membership
Check file exits and filepath you r passing is nil:
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"example" ofType:#"mp4"];
if([[NSFileManager defaultManager] fileExitsAtPath:filepath])
{
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
else
{
NSLog(#"File not exists");
}

Could not load NIB in bundle ImageViewCell

I'm getting this error while running simulator. The project was not created on this environment, not sure I'm missing a configuration setting.
Error
2012-08-08 19:30:56.411 ACME[4068:f803] mItemArray.count: 2 2012-08-08 19:30:56.413 ACME[4068:f803] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'ImageViewCell''
if(cell == nil)
{
NSArray *array = [[NSBundle mainBundle] loadNibNamed:#"ImageViewCell" owner:self options:nil];
cell = [array objectAtIndex:0];
}
You have not set the "files owner" in the NIB file to the owner you are setting in code. The NIB loader will fail like this when it cant link the objects in the NIB to the right root owner.
The name after "loadNibNamed:" must be the name of the nib file (in project navigator on the left side of the screen), sometimes people write there 'cell identifier' that writes from the start in CellForRowAtIndexPath (static NSString ...).
May be your problem in this little fault?