2012-03-21 14 views
5

Moja aplikacja używa menedżera konta do udostępniania tokena autoryzacji i działa poprawnie na początku 4.0. Ale kiedy próbuję aplikacji na moim Nexusie S (4.0.3), NPE pojawia się za każdym razem, gdy wywołuję metodę getAuthToken. Ślad stosu następująco:getAuthToken nie działa to ICS

E/AndroidRuntime(5282): java.lang.RuntimeException: Unable to start activity ComponentInfo{android/android.accounts.Gra 
ntCredentialsPermissionActivity}: java.lang.NullPointerException 
E/AndroidRuntime(5282):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 
E/AndroidRuntime(5282):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
E/AndroidRuntime(5282):  at android.app.ActivityThread.access$600(ActivityThread.java:123) 
E/AndroidRuntime(5282):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
E/AndroidRuntime(5282):  at android.os.Handler.dispatchMessage(Handler.java:99) 
E/AndroidRuntime(5282):  at android.os.Looper.loop(Looper.java:137) 
E/AndroidRuntime(5282):  at android.app.ActivityThread.main(ActivityThread.java:4424) 
E/AndroidRuntime(5282):  at java.lang.reflect.Method.invokeNative(Native Method) 
E/AndroidRuntime(5282):  at java.lang.reflect.Method.invoke(Method.java:511) 
E/AndroidRuntime(5282):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
E/AndroidRuntime(5282):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
E/AndroidRuntime(5282):  at dalvik.system.NativeStart.main(Native Method) 
E/AndroidRuntime(5282): Caused by: java.lang.NullPointerException 
E/AndroidRuntime(5282):  at android.accounts.GrantCredentialsPermissionActivity.onCreate(GrantCredentialsPermissi 
onActivity.java:84) 
E/AndroidRuntime(5282):  at android.app.Activity.performCreate(Activity.java:4465) 
E/AndroidRuntime(5282):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 
E/AndroidRuntime(5282):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 
E/AndroidRuntime(5282):  ... 11 more 
W/ActivityManager( 151): Force finishing activity android/.accounts.GrantCredentialsPermissionActivity 

Ale kiedy się Google'a AuthToken, to działa dobrze. Moje pytanie brzmi: Czy coś jest nie tak w moim kodzie i jak mogę to naprawić? Czy jest to błąd w systemie Android, który zostanie naprawiony później?

+2

Ktoś zgłosił problem błędu dla tego http://code.google.com/p/android/issues/detail?id=23421 – rds

Odpowiedz

1

Ten problem został zabija mnie przez jakiś czas, ale ten pracował dla mnie na ICS 4.0.3:

AccountManager am = AccountManager.get(context); 
Account[] accounts = am.getAccountsByType("com.google"); 
Account selected = accounts[0]; 
am.getAuthToken(account, "ah", false, callback, null); 

Gdzie zwrotna "wygląda trochę coś takiego:

new AccountManagerCallback<Bundle>() { 

@Override 
public void run(AccountManagerFuture<Bundle> future) { 
    Bundle bundle; 

    try { 

     bundle = future.getResult(); 
     Intent intent = (Intent)bundle.get(AccountManager.KEY_INTENT); 
     if(intent != null){           

      startActivity(intent); 
    //In the activity that runs this I check for a flag in the onResume, which tells me that we returned from this activity 

     } 
     else{ 
      //we have the token! 
     } 

    } catch (OperationCanceledException e) { 

    } catch (AuthenticatorException e) { 

    } catch (IOException e) { 

    } 

    } 
} 

Ta metoda nie zwraca GrantCredentialsPermissionActivity, zwraca inny, podobny do "LoginActivity".

Nadzieja to pomaga

+0

Ale co z kont innych niż Google? –

+0

Nie próbowałem z żadnymi kontami innymi niż Google. – Theblacknight

+0

Ten błąd występuje we mnie, zanim sparametryzowane wywołanie zwrotne zostanie osiągnięte. Ale to, co rozwiązało to za pomocą 'getAccountsByType (String s)' zamiast 'getAccounts()'. (Zgodnie z sugestią na stronie: http://stackoverflow.com/questions/13577100/google-drive-sdk-error) – Robadob

Powiązane problemy