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

  • Home
  • SEARCH
  • 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 6341557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:03:36+00:00 2026-05-24T20:03:36+00:00

In my Piano class, I have a property (Keys is another custom class) @property

  • 0

In my Piano class, I have a property (Keys is another custom class)

@property (nonatomic, retain) Keys *lastPlayed;

In one of my Piano methods, I set the value of lastPlayed using an object from an array of Key objects.

self.lastPlayed = [allKeys objectAtIndex:variable];

The above line of code causes the program to crash.

I’ve noticed that if I hardcode a specific Key object from the allKeys array, then it works fine. Like so:

self.lastPlayed = keyC;

Interestingly, it doesn’t crash if I put the crashing code into a different method.

How can I prevent the crash?

EDIT:

I call this method in the Keys class, where my piano is the delegate

[delegate deliverTagwithNameTag:self.tag]

the piano then responds

- (void) deliverTagwithNameTag:(int)nameTag {

self.lastPlayed = [allKeys objectAtIndex:nameTag];

}
  • 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-05-24T20:03:37+00:00Added an answer on May 24, 2026 at 8:03 pm

    You’re probably not getting a plain unexplained crash, you’re probably raising an exception. You can watch the console to find out which exception you raised. Normally in this sort of situation it’ll be something useful to tell you either that you’re asking the array for an out-of-bounds value (which could happen if variable were collecting an incorrect value somehow), that the array itself is invalid (which could be a memory allocation problem) or that the thing returned can’t be stored as lastPlayed (which would normally indicate you’re doing something custom in the setter and getting an unexpected type of class).

    So to prevent the crash, check your console and look for one of those problems.

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

Sidebar

Related Questions

I have a client who requested piano keys as links and he wants them
I have a custom view which has a piano keyboard drawn inside of it.
I have a custom view that fills my entire screen. (A piano keyboard) When
I have a piano UIView, made of Key subviews. The keys are assigned their
I'm making a piano application in Java. This is one of the functions, public
I work on a synthesizer where I would like to have a keyboard/piano displayed
I have a piano keyboard. Each button (key of the piano) has a different
I will simulate a piano key-board in android pad. When use press one key,
I am developing a piano in C#. I have the following piece of code
I'm overriding the touches methods in a UIView for a piano app. If I

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.