0

XCode と Objective-C は初めてです。アプリをシミュレーターで実行すると、この例外が発生します。iPadでは問題なく動作します。AVaudioPlayer が割り当てられると、警告 SIGSTOP で停止します。

誰か提案はありますか?これは重大な例外ですか?前もって感謝します!

「スタック トレース」の場所がわからないので、RUN デバッガーを gdb に配置しました。この情報から: Pending breakpoint 1 - ""soundScape.m":112"
resolve rndmitem
amount
url

SIGSTOP の前の行は次のとおりです。

libc++abi.dylib`__cxa_throw:
0x46e4a44: pushl %ebp
0x46e4a45: movl %esp, %ebp

現在の言語: auto; 現在、objective-c
0x1 は有効なオブジェクトを指していないようです。
0x2 は有効なオブジェクトを指していないようです。
file://localhost/Users/myName/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/E92E5F03-0B07-4AF0-BFB4-E1F7009A4E78/babyschets.app/02Seawash.mp3
[プロセス 81163 スレッド 0x1720b に切り替え]
[プロセス 81163 スレッド 0x15803] への切り替えは、 例外 状態


レジスタの下に あり ます。





randomItem :
(NSUInteger) $0 = 1 [Objective-C の説明はありません]
amountOfAudioFiles :
(int) $1 = 2 [Objective-C の説明はありません]
url :
(NSURL *) $2 = 0x07485860
file://localhost/Users/myName /ライブラリ/Application%20Support/iPhone%20Simulator/5.1/Applications/E92E5F03-0B07-4AF0-BFB4-E1F7009A4E78/babyschets.app/02Seawash.mp3

audioFiles1 :
(NSArray *) $4 = 0x0747d720 <__NSArrayI 0x747d720>(
01Seawash.mp3,
02Seawash.mp3
)

int amountOfAudioFiles = [audioFiles1 count];
NSUInteger randomItem = arc4random()%(int)amountOfAudioFiles;

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:[NSString stringWithString:[audioFiles1 objectAtIndex:randomItem]]
                                     ofType:nil]];

NSError *error;

audioPlayer1 = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];

OK、このコードをきれいにしました。ここに私の解決策があります。今では魅力のように実行されています:

.h ファイル内: @property (非アトミック、保持) AVAudioPlayer *audioPlayer1;

.m ファイル内:

int amountOfAudioFiles = [audioFiles1 count];
int randomItem = (int)(arc4random()%amountOfAudioFiles);
if (randomItem < 0) randomItem = 0;

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:[NSString stringWithFormat:@"%@", [audioFiles1 objectAtIndex:randomItem]]
                                     ofType:nil]];


if (audioPlayer1) {
    if (audioPlayer1.isPlaying) {
        [audioPlayer1 stop];
        audioPlayer1 = nil;
    }

} else {
    audioPlayer1 = [AVAudioPlayer alloc];
}

NSError *error;
audioPlayer1 = [audioPlayer1 initWithContentsOfURL:url error:NULL];
4

1 に答える 1

0

これは、オブジェクト (フレームワーク内) が iOS バージョンに存在しないことを意味します。おそらく、アプリをテスト/実行している iOS デバイスの iOS を更新する必要があります。

于 2012-09-18T13:33:39.997 に答える