main.m error in iPhone build - iphone

Never thought I'd get an error in this file when I compiled, but after running my app in debug mode, The app stops and highlights the line
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
in my main.m file as a breakpoint. When I run in normal mode, the app just shows a black screen. What does this mean?
(Update)
Okay, nothing has worked so far. Here is the code that is failing:
#import <UIKit/UIKit.h>
int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
The stack says
Pending breakpoint 1 - ""main.m":31" resolved
The weird thing is, I removed the aforementioned view controller that preceded this problem, there are still no warning or errors and I the application still either halts in debug mode or returns a black screen and freezes in normal running mode.
Here is a drop containing two screenshots of my view and window arrangements in my two NIBs in IB. You can also download my full project to browse the code, if you wish. The project is named "iHouse.zip"
http://drop.io/6lhubkb
Otherwise, any other specific code anyone would like to see, I'm happy to paste it here on request. Otherwise, I'm stumped.
Thanks.

Solved....sort of. The "31" in the stack was oddly referring to a random line in the commented out apple disclaimer in the beginning of main.m. I removed this and that problem went away. Still not sure why it suddenly became a problem in the first place.
I compared the code side-by-side with another app and found that I had commented out a critical part of applicationDidFinishLoading in the AppDelegate as #IWasRobbed had suggested.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
[window addSubview:splitViewController.view];
[window makeKeyAndVisible];
}
else
{
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
}
Because I was not ready to make this app universal, I commented this part out. In doing so, I took out the crucial piece to tell the app what the heck to load in the first place
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
Thanks everyone for your help. Took all day to find a silly error on my part, but you live and you learn I guess.

It means you probably forgot to hook up a window or view to load after the application launches. Unless you modified the main.m file (which you shouldn't need to), it should be just fine.

Related

Create calendar event from inside my application

I know that there already are lots of questions and even useful answers concerning this question on the web. I tried to add a calendar event to the iPhone calendar from inside my application. I used this code, which actually worked:
EKEventStore *es = [[EKEventStore alloc] init];
EKEventEditViewController *controller = [[EKEventEditViewController alloc] init];
controller.eventStore = es;
controller.editViewDelegate = self;
[self presentModalViewController:controller animated:YES];
The only thing was that I could not release the calendar controller, which is because I should have said:
[Controller release]
or something
But my main.m is set to autorelease:
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([...AppDelegate class]));
}
}
and if I manually release I get an error, do I have to change something in the main.m?
In your target's build settings, if you see Objective-C Automatic Reference Counting then you are using ARC:
And if you are using ARC then you are not responsible to release object by your self.
I strongly recommend to read more about ARC, you can start from here, this is the most important thing you should consider if you want to build a real application.
As I understand from the comments, it might be you are using ARC. In order to check that, go on your project tab, select Build Settings and type in the search bar
Automatic Reference Counting
If it's set to you YES, you don't need to release the object.
EDIT
It looks like there have been a misunderstanding regarding the word release. Release as you mentioned it (calling release on an object) means to decrease the object reference counter.
Dismissing a modal view controller is a complete different thing. In order to do that,
on the cancel button delegate method, you have to invoke:
[yourViewControllerInstance dismissModalViewControllerAnimated:YES];
That's the method you are searching for.

Sometimes my project works fine, sometimes it shows following error in the line mentioned in the code below

#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);//Program received signal: EXC_BAD_Access"
[pool release];
return retVal;
}
You’re accessing bad memory somewhere. Most probably, you're trying to reference a pointer to an object that's been released already, and the debugger has had to roll back to the bottom of the stack. Usually, a hint to the real reason for a crash like this will appear just slightly before "Program received signal: EXC_BAD_Access" in the log.
Good luck.
EXC_BAD_Access means you're overreleasing an object. Run the app using Instruments Object Alloc with Zombie detection enabled to find the culprit.
Your application going to crash that's why you are getting error at this point,
you can check where application going to crash by selecting iOs Simulator 4.3 and lower version.
This may help you to debug the problem.
iOS 5.0 and later never tell where is the issue for that you must have to run you app in lower version then 5.0.

Puzzling Error on Iphone AddSubView function

if(popup != nil) {
[popup.view removeFromSuperview];
[popup release];
}
popup = [[OfferPopup alloc] initWithNibName:#"OfferPopup" bundle:nil];
popup.offer = offer1;
popup.delegate = self;
[self.view addSubview:popup.view];
1)The App crashed when trying to do the addSubView popup.view
2)I stepped through the code and checked offer1 is valid, popup is valid has a memory address. popup is a view controller.
3)The current module is a viewcontroller too.
4)The App crashed due EXEC_BAD_ACCESS.
5)I used performance tool and enabled Zombie checking, and ran it, again the app crashed without the performance tool indicate where the reference count goes wrong.
I am puzzled as how to troubleshoot.
Check if Popup xib file exists, or see if you are naming it right in your initialisation code. See if the viewController class is correctly assigned in File Owner in IB.

iPhone SDK "clear" function not working-button

I have a question relating to a button I made for my app. I am fairly new to iPhone development so please stay with me. When the "clear" button is clicked, it is programmed to reset the text fields. The other "calculate" function works fine. The app runs perfectly until I press "clear". Then the app will completely freeze. The following is displayed in Xcode.The commented out is the error I get, I think it is some sort of breaker:
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
//Above error reads "Thread 1: Program received signal: "SIGABRT"
[pool release];
return retVal;
}
I feel like this is a simple mistake but I am unfamiliar with mobile development and just started it. Any help would be greatly appreciated!!
When this occurs, it usually means Xcode couldn't figure out where something went wrong. The best thing to do is to set a breakpoint in the first line of your -clearButtonWasPushed: method (or equivalent). Run it step by step, and then when it crashes to your main.m code, you'll know which line caused it. You might have overreleased something by mistake...
Alternatively, UITextField has a built in clear button, which you can activate programatically or in IB:
textField.clearButtonMode = UITextFieldViewModeWhileEditing;

How UIWindow#addSubview can make memory leak?

I started to learn using Instrument, but I cannot figure it out.
After I start my application, the UI shows up, I do nothing and after few seconds I can see memory leak detected:
When I have a look at the second leak I can see the following stack:
When I double click on the cell related to my code I can see that it is pointing to the following line of code:
[window addSubview:newPostUIViewController.view];
from the method:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
//creating view controller
newPostUIViewController = [[NewPostUIViewController alloc] initWithNibName:#"NewPostView" bundle:nil];
newPostUIViewController.title = #"Post it!";
[window addSubview:newPostUIViewController.view];
// Override point for customization after application launch
[window makeKeyAndVisible];
}
I wonder, how this can be a reason of a leak? I release newPostUIViewController in the dealloc method of PostItAppDelegate class.
Any ideas how this could be explained?
You did not provide an autorelease or release to balance your init. Just in case you haven't read through it already, have a look at the memory management guide is a great help.
Looking at link text allows to say that this is Simulator problem, not the code problem.