Note that there are some explanatory texts on larger screens.

plurals
  1. POAssertion Failure in Calculator Program
    text
    copied!<p>So I'm working on a simple calculator program to get used to cocoa and objective C. I've redone the whole thing multiple times and every time I finish coding, the first time i build it, it works fine, but every time after that the window wont launch and it gives me these errors:</p> <pre><code>2013-01-11 10:32:14.760 Visual Caluclator Fix[39892:403] *** Assertion failure in -[NSTextFieldCell _objectValue:forString:errorDescription:], /SourceCache/AppKit/AppKit-1138.47/AppKit.subproj/NSCell.m:1564 2013-01-11 10:32:14.762 Visual Caluclator Fix[39892:403] Ignoring exception raised in __-[NSPersistentUIManager restoreAllPersistentStateWithTalagentWindows:registeringAsReadyWhenDone:completionHandler:]_block_invoke_3: Invalid parameter not satisfying: aString != nil </code></pre> <p>I've concluded that the problem lies in my textEdited method, because when I comment the code inside of it out, the program has no issues running; however, I have no idea why this is, or why it would run the first time and not any subsequent times. When I put in an exception breakpoint, it points me to the one line in the updateUI method and the call to [self updateUI] in the textEdited method. The following code is the textEdited method and the other methods it references.(I'm fairly sure there's nothing wrong with the solve method because I used it in a command prompt calculator and it worked great. Also, I know this is a pretty convoluted way to program a calculator, with the strings and everything, but I was just trying to integrate the code I already had for the command prompt program into a cocoa program.)</p> <p>In the AppDelegate class:</p> <pre><code>- (void)updateUI{ [self.calculationView setStringValue: self.calculation.calcString];//Exception breakpoint points here } - (IBAction)textEdited:(id)sender { self.calculation.calcString = self.calculationView.stringValue; [self.calculation solve]; [self updateUI];//Exception breakpoint points here } </code></pre> <p>In the Calculation class:</p> <pre><code>- (NSString*)solve{ for (int i = 0; i &lt; [self.calcString length]; i++) { NSRange nextChar = NSMakeRange(i, 1); if ([[self.calcString substringWithRange: nextChar] isEqualToString: @"*"]|| [[self.calcString substringWithRange: nextChar] isEqualToString: @"/"]) [self calcTerm: i]; } for (int i = 0; i &lt; [self.calcString length]; i++) { NSRange nextChar = NSMakeRange(i, 1); if ([[self.calcString substringWithRange: nextChar] isEqualToString: @"+"]|| [[self.calcString substringWithRange: nextChar] isEqualToString: @"-"]) [self calcTerm: i]; } return self.calcString; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload