views:

155

answers:

2

Hi,

since yesterday I've got a bug in my application and I don't get where it is. Actually I am pretty sure that I did not change anything and that it worked perfectly yesterday.

I do not intent to publish all of the code but I can post my first ViewController, if you want.

The problem occurs in both ViewControllers. I use the MGTwitterEngine-API to send a message to Twitter. As far as I know the bug causing a crash is located in the following line.

MGTwitterEngine *twiit = [[MGTwitterEngine alloc] initWithDelegate:self];
[twiit setUsername:usernamee password:passworde];

I thought there is nothing wrong about it. Am I wrong? usernamee and passworde are NSStrings.

The console returns:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[MGTwitterEngine setUsername:password:]: unrecognized selector sent to instance 0x3911fb0'

If there are questions or if it's impossible to solve the problem like that i would agree to send my hole code to somebody for check. It is not very complex and it just has to Views. Stil I just send the code to trustworthy persons with many reputations.

In addition I am sure that there is nothing wrong about the MGTwitterEngine since I did not ever change its code. It worked probably and I even copied a fresh MGTwitterEnginge into the project's folder.

Oh and here the UIAction, which reacts on a button and let the app crash:

    - (IBAction) post: (id) sender{


        NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
        NSString *usernamee;
        usernamee = [prefs stringForKey:@"name_preference"];
    //everthing works great, I checked, that usernamee got the right Nsstring from the preference
        NSString *passworde;
        passworde = [prefs stringForKey:@"password_preference"];

MGTwitterEngine * twitter1 = [[MGTwitterEngine alloc] initWithDelegate:self];
        [twitter1 setUsername:usernamee password:passworde];
        NSLog(@"sendUpdate: connectionIdentifier = %@", [twitter1 sendUpdate:[@""stringByAppendingString:twittermessage.text]] ); //It is not important, if I use sendUpdate, getDirectMessagesSinceID and so on...
            loadingActionSheet = [[UIActionSheet alloc] initWithTitle:@"Posting to Twitter..." delegate:nil 
                                                    cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
            [loadingActionSheet showInView:self.view];
    }
A: 

It's possible your preferences do not actually contain the values you asked for - in which case it will not have returned strings, and you could be getting the NSInvalidArgument exception.

You can check this:

 if (![passworde isKindOfClass:[NSString class]] || ![usernamee isKindOfClass:[NSString class])
  {
    NSLog(@"Some problem with your preferences");
  }

isKindOfClass Documentation

Alex Brown
They are contain the right values, i asked for: 1.) I can ceck the values in the settings-app of the iphone. 2.) I wrote NSLog(@"%d",usernamee) and it worked. The console wrote the right username. 3.)I also tried: [twitter1 setUsername:@"aString" password:@"aString"];
Flocked
I guess password was OK, as well. I don't recognise your NSLog, for some reason, I would have expected NSLog(@"%@", usernamee);.
Alex Brown
I also tried your code and the console doesnt return "Some problem blah".Sorry I mean @"%@", usernamee)
Flocked
could I send you my xcode-project-data? I would be very happy because this unknown error given me a really bad mood.
Flocked
Only if you can first whittle the problem down to just the code that breaks - 20 lines or so, total. I want to avoid having more than a tiny amount of code that you 'own'.
Alex Brown
Haha great - Thanks for your help! :) I just deleted everything down to the problem and than undo everything I deleted. Now it just works. But I can not say, why... Any idea? :D
Flocked
sometimes a `make clean` solves everything. I was going to suggest it before, but you've probably forced the build system to do it for you.
Alex Brown
+1  A: 

This code works fine for me. Are you getting any compiler warnings about the "unrecognized selector"?

gerry3
No, there is no compilerwarning about that. - The strange thing is, that I´m pretty sure, that the code worked yesterday… And I didnt changed something until than.
Flocked
Or could I send you the xcode-project? As I said I would be very happy because this unknown error given me a really bad mood.
Flocked