2013-09-24 61 views
1

這裏是我的代碼來整合Facebook與Android應用程序(parse.com)。整合Facebook +解析在Android應用程序中的錯誤

請找到下面的代碼和堆棧trace.here試圖從解析驗證FB用戶。

當你點擊login with Facebook選擇應用程序崩潰。任何建議將不勝感激。

private void onLoginButtonClicked() { 
     // TODO Auto-generated method stub 
     LoginActivity.this.progressDialog = ProgressDialog.show(
       LoginActivity.this, "", "Logging in...", true); 
     List<String> permissions = Arrays.asList("basic_info", "user_about_me", 
       "user_relationships", "user_birthday", "user_location"); 

     // ParseFacebookUtils.initialize(appId); 
     ParseFacebookUtils.logIn(permissions, this, new LogInCallback() { 
      @Override 
      public void done(ParseUser user, ParseException err) { 
       LoginActivity.this.progressDialog.dismiss(); 
       if (user == null) { 
        Log.d(IntegratingFacebookTutorialApplication.TAG, 
          " user cancelled the Facebook login."); 
       } else if (user.isNew()) { 
        Log.d(IntegratingFacebookTutorialApplication.TAG, 
          "User signed up and logged in through Facebook!"); 
        showUserDetailsActivity(); 
       } else { 
        Log.d(IntegratingFacebookTutorialApplication.TAG, 
          "User logged in through Facebook!"); 
        showUserDetailsActivity(); 
       } 
      } 
     }); 
    } 

日誌

09-24 18:33:35.809: E/AndroidRuntime(641): FATAL EXCEPTION: main 
09-24 18:33:35.809: E/AndroidRuntime(641): java.lang.IllegalStateException: You must call ParseFacebookUtils.initialize() before using ParseFacebookUtils 
09-24 18:33:35.809: E/AndroidRuntime(641): at com.parse.ParseFacebookUtils.checkInitialization(ParseFacebookUtils.java:88) 
09-24 18:33:35.809: E/AndroidRuntime(641): at com.parse.ParseFacebookUtils.logIn(ParseFacebookUtils.java:331) 
09-24 18:33:35.809: E/AndroidRuntime(641): at com.parse.ParseFacebookUtils.logIn(ParseFacebookUtils.java:355) 
09-24 18:33:35.809: E/AndroidRuntime(641): at com.tukutane.LoginActivity.onLoginButtonClicked(LoginActivity.java:168) 
09-24 18:33:35.809: E/AndroidRuntime(641): at com.tukutane.LoginActivity.onClick(LoginActivity.java:154) 
09-24 18:33:35.809: E/AndroidRuntime(641): at android.view.View.performClick(View.java:4084) 
09-24 18:33:35.809: E/AndroidRuntime(641): at android.view.View$PerformClick.run(View.java:16966) 
09-24 18:33:35.809: E/AndroidRuntime(641): at android.os.Handler.handleCallback(Handler.java:615) 
09-24 18:33:35.809: E/AndroidRuntime(641): at android.os.Handler.dispatchMessage(Handler.java:92) 
09-24 18:33:35.809: E/AndroidRuntime(641): at android.os.Looper.loop(Looper.java:137) 
09-24 18:33:35.809: E/AndroidRuntime(641): at android.app.ActivityThread.main(ActivityThread.java:4745) 
09-24 18:33:35.809: E/AndroidRuntime(641): at java.lang.reflect.Method.invokeNative(Native Method) 
09-24 18:33:35.809: E/AndroidRuntime(641): at java.lang.reflect.Method.invoke(Method.java:511) 
09-24 18:33:35.809: E/AndroidRuntime(641): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
09-24 18:33:35.809: E/AndroidRuntime(641): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
09-24 18:33:35.809: E/AndroidRuntime(641): at dalvik.system.NativeStart.main(Native Method) 

回答

3

你必須調用這個

ParseFacebookUtils.initialize(appId); 

ParseFacebookUtils.logIn(); 
3
09-24 18:33:35.809: E/AndroidRuntime(641): java.lang.IllegalStateException: You must call ParseFacebookUtils.initialize() before using ParseFacebookUtils 

你初始化解析過ls在調用登錄之前? 至少您共享的日誌文件表示您沒有這樣做。

請對以下方法的調用:

ParseFacebookUtils.initialize()  

你打電話

Parse.Initialize() 
+0

中的onCreate綁這個(); Parse.initialize(這一點, 「ASFolIoL4cWIs7pxHzbGOLR0Kj0LQ7f1tQGh4HwR」, \t \t \t \t 「8HXvQPTaSQWuUJKjJyn6OMFU1snfL8iO8qX0HmKJ」); \t \t ParseAnalytics.trackAppOpened(getIntent()); 什麼? – user1987430

+0

@ user1987430你做Parse.initialize()NOT ParseFacebookUtils.initialize() –

+1

@ user1987430僅供參考,我知道它的六個月中下旬左右,但你應該永遠不離開你的應用程序ID /客戶端密鑰,這樣的消息。可能是一個真正的糟糕時間,如果有人得到這個,他們想惡作劇/惡作劇在你的應用程序。 – CBanga

0

使用應用程序類這樣

public class SampleApp extends Application { 


private static String PARSE_APPLICATION_ID; 
private static String PARSE_CLIENT_KEY; 

@Override 
public void onCreate() { 
    super.onCreate(); 

    PARSE_APPLICATION_ID = getResources().getString(R.string.PARSE_APPLICATION_ID); 
    PARSE_CLIENT_KEY = getResources().getString(R.string.PARSE_CLIENT_KEY); 
    Log.d(tag, "initializing with keys"); 
    // Add your initialization code here 
    Parse.initialize(this, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY); 
    // This allows read access to all objects 
    ParseACL defaultACL = new ParseACL(); 

    defaultACL.setPublicReadAccess(true); 
    defaultACL.setPublicWriteAccess(true); 

    ParseACL.setDefaultACL(defaultACL, true); 

    Log.d(tag, "initializing app complete"); 
} 
} 

清單中

添加此我希望這將是我清除錯誤。

+0

爲什麼你要在清單中添加這個?它應該在一個單獨的類,如Man.java –

+0

我的意思是在清單中添加此應用程序類。 –

0

對於大家,應用程序標籤:)下的清單中指定它得到你實際上是使用自定義的應用程序類此異常仔細檢查

<application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" 
     android:name=".CustomApplicationClassName"> 
相關問題