开发者

Error when using MD5 algorithm

I'm trying to run this MD5 algorithm, which I found on this post on stackoverflow . But I keep on getting the following error:

2010-08-06 14开发者_JAVA技巧:45:40.971 Intel[3195:a0f] -[TaskController md5:]: unrecognized selector sent to instance 0x108df0
2010-08-06 14:45:40.973 Intel[3195:a0f] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TaskController md5:]: unrecognized selector sent to instance 0x108df0'
*** Call stack at first throw:
(
0   CoreFoundation                      0x9875abba __raiseError + 410
1   libobjc.A.dylib                     0x96a3a509 objc_exception_throw + 56
2   CoreFoundation                      0x987a78db -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3   CoreFoundation                      0x987017e6 ___forwarding___ + 950
4   CoreFoundation                      0x987013b2 _CF_forwarding_prep_0 + 50
5   Intel                               0x00003143 -[TaskController findFileOrCreateFile] + 709
6   Intel                               0x00002d29 -[TaskController init] + 92
7   Intel                               0x00002c03 main + 128
8   Intel                               0x00002a6a start + 54
)

I though it might have something to do with my string being UTF-8, but I have tried inputting the following string and still get errors:

NSString *foo = @"your text here";
const char *bar = [foo UTF8String];

Any help?

Thanks so much


It doesn't have anything to do with your string format. The runtime is looking for your md5 method and not finding it. Did you define it in your @interface section of your TaskController object? Did you define/call it with the right number of parameters?


Read the exception message:

-[TaskController md5:]: unrecognized selector sent to instance 0x108df0

You tried to send an md5: message to an instance that does not recognize such messages.

5   Intel                               0x00003143 -[TaskController findFileOrCreateFile] + 709

And this is where you tried to send it from.

As you revealed in your comment on Wade Williams's answer, the cause of your problem was that you had declared and defined the method as a class method (+[TaskController md5:]). Note how your declaration had a + where the exception shows a -; the problem is the mismatch.

Since you were sending the message to a TaskController instance, not the TaskController class, the solution was and is to change the declaration to an instance method (-[TaskController md5:], like the exception message says). The other solution would have been to leave it as a class method and change the message expression to send the message to the class rather than an instance (hash = [TaskController md5:str]).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜