Error: Class not found when unmarshalling: com.fac

2020-03-12 03:11发布

I am getting this error when hitting the "Login With Facebook" (Simple login button).

I have Google, and read other topics here - but I can not see any thing matching my issue.

I am adding Login.java class below.

public class Login extends Activity {



/**
 * Called when the activity is first created.
 */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_login);
    CallbackManager callbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions("public_profile", "email", "user_friends");

    // Other app specific specialization

    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {


        @Override
        public void onSuccess(LoginResult loginResult) {

            Log.i("Login", "Logged in: ");
          Intent i = new Intent(Login.this, MainActivity.class);
            startActivity(i);
        }

        @Override
        public void onCancel() {
            // App code

        }

        @Override
        public void onError(FacebookException exception) {
            // App code
            Log.i("Error" , "Error");
        }


    });
}
}

StackTrace:

            05-28 20:07:27.550     872-1363/? E/Parcel﹕ Class not found when unmarshalling: com.facebook.login.LoginClient$Request
            java.lang.ClassNotFoundException: com.facebook.login.LoginClient$Request
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:308)
            at java.lang.Class.forName(Class.java:272)
            at android.os.Parcel.readParcelableCreator(Parcel.java:2275)
            at android.os.Parcel.readParcelable(Parcel.java:2239)
            at android.os.Parcel.readValue(Parcel.java:2146)
            at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
            at android.os.BaseBundle.unparcel(BaseBundle.java:221)
            at android.os.BaseBundle.getString(BaseBundle.java:918)
            at android.content.Intent.getStringExtra(Intent.java:5378)
            at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1768)
            at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:1313)
            at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:4522)
            at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:4368)
            at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:140)
            at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2964)
            at android.os.Binder.execTransact(Binder.java:446)
             Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.login.LoginClient$Request" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:308)
            at java.lang.Class.forName(Class.java:272)
            at android.os.Parcel.readParcelableCreator(Parcel.java:2275)
            at android.os.Parcel.readParcelable(Parcel.java:2239)
            at android.os.Parcel.readValue(Parcel.java:2146)
            at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
            at android.os.BaseBundle.unparcel(BaseBundle.java:221)
            at android.os.BaseBundle.getString(BaseBundle.java:918)
            at android.content.Intent.getStringExtra(Intent.java:5378)
            at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.j

           Java:1768)      at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:1313)
          at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:4522)
            at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:4368)
            at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:140)
            at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2964)
            at android.os.Binder.execTransact(Binder.java:446)
             Suppressed: java.lang.ClassNotFoundException: com.facebook.login.LoginClient$Request
            at java.lang.Class.classForName(Native Method)
            at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
            at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
            ... 18 more
           Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

8条回答
孤傲高冷的网名
2楼-- · 2020-03-12 03:27

I too had this issue. Mine however was a login call made within the FBActivity.OnResume method for callbacks to login after accepting fb perms.

I simply moved the request into the profile tracker in the onCreate method

    ProfileTracker profileTracker = new ProfileTracker() {
        @Override
        protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {

            Profile.fetchProfileForCurrentAccessToken();
            if(currentProfile != null) {
                String fbUserId = currentProfile.getId();
                profileUrl = currentProfile.getProfilePictureUri(200, 200).toString();
                Log.d("FB profile", "got new/updated profile from thread " + fbUserId);

                // jump if logged in already
                GetFacebookProfileAndJump(currentProfile);

            }

        }
    };

Also ensure your OnCreate super is as follows

    FacebookSdk.sdkInitialize(getApplicationContext());
    mCallbackmanager = CallbackManager.Factory.create();
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_fbauth_);

...

查看更多
3楼-- · 2020-03-12 03:29

I have struggled with this problem and I fixed with multidex enabled

add this in your build file

multiDexEnabled true

also this code in your activity

@Override   
protected void attachBaseContext(Context context) {
         super.attachBaseContext(context);
         MultiDex.install(this);
}

after adding this in your build gradle dependencies

compile 'com.android.support:multidex:1.0.1'
查看更多
时光不老,我们不散
4楼-- · 2020-03-12 03:32

In my case i forgot to add application package name and class name on the developer page of facebook. After i added this information then it worked.

查看更多
你好瞎i
5楼-- · 2020-03-12 03:36

You should add this to your acctivity

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)            {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);

}

but if your using parse SDK add this

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    ParseFacebookUtils.onActivityResult(requestCode, resultCode, data);
}
查看更多
何必那么认真
6楼-- · 2020-03-12 03:39

I had the same problem, and solved by putting the facebook_app_id to strings.xml instead of a constant:

<meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id" />
查看更多
Rolldiameter
7楼-- · 2020-03-12 03:41

Check your android:noHistory flag on the activity.

See link https://developers.facebook.com/bugs/1621984714705591/ look for post by Andreas Bergenwall

查看更多
登录 后发表回答