Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8921719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:37:33+00:00 2026-06-15T06:37:33+00:00

I am trying to make a square button for a calculator, it should take

  • 0

I am trying to make a square button for a calculator, it should take the value from the MainLabel, multiply it with itself and then update it to show the result.

The code I’m using is :

- (IBAction)squarePressed:(id)sender
{

    NSString *mainLabelString = mainLabel.text;

    int mainlabelValue = [mainLabelString intValue];

    NSString *calculatedValue = ((mainlabelValue)*(mainlabelValue));

    mainLabel.text = calculatedValue;

} 

When I press the button in the simulator, it pauses and thread 1 says this for the last line;

Thread 1: EXC_BAD_ACCESS (code=2, address= 0x51) 

What does this mean, what should I do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:37:35+00:00Added an answer on June 15, 2026 at 6:37 am

    It means that you try to access an object where there is none. A message has been sent to an object that has either been deallocated or to a pointer that points to garbage in the memory.

    You should set a breakpoint in your method and debug; in order to see if your code is hit. If it is, it is simply a matter of stepping through and identifying the offending line, then figuring out which pointer is bad (try printing the objects with the debugger).

    It is impossible for us to know the exact source of your error, but if I should try to guess based on your code, perhaps you forgot to hookup mainLabel in Interface Builder, and therefore it does not point to a valid label when your method is run ?

    The next (and more likely) source of your error is that you assign the mainLabel.text pointer an integer value. You should get a warning here, but if you ignore that, the integer will be assigned as a pointer. Obviously the chances of that integer being a pointer to a valid ObjC object is very slim, so the program fails when it tries to access mainLabel.text again. As explained in another answer, you should create a string with the number:

    NSString *calculatedValue = [NSString stringWithFormat: @"%d", mainLabelValue*mainLabelValue];
    

    Was the number you tried with when you got the error by any chance 9 ? The message says you tried to access memory location 0x51, which coincidentally is 81 = 9*9 in decimal. Using stringWithFormat to format the number as a string, and assigning the returned string pointer to the string pointer property mainLabel.text will resolve your issue. You need to be careful about your types.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a calculator and when trying to make the square root function, it
Im Trying to make a red square move from top of view to a
Trying to make the infamous checkall checkbox for dynamically created rows from a MySQL
Trying to make a cross protocol, same domain request from https to http. I
Trying to make td elements clickable. Here's my HTML: <td id=A3 class= open-square><a href=/gameplay/A3></a></td>
I'm trying to make an application with flash builder that performs operations on square
I'm trying to make a square plot (using imshow), i.e. aspect ratio of 1:1,
I'm using Ruby Qt bindings. I'm trying to make a square widget (checker board),
I am trying to make a breadth-first search to solve a square-shifting puzzle (the
i'm trying to make an application, getting all the birthdays and other information from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.