扩展类com.facebook.widget.ProfilePictureView时出错

时间:2017-05-30 14:43:52

标签: java android facebook facebook-android-sdk

我试图制作一个应用程序,在其中我尝试获取已登录用户的个人资料照片。

当我进入我加载图片的视图并且我无法理解错误时,我有一个很长的错误。

错误是:

        FATAL EXCEPTION: main
    Process: com.chinchillapps.compare, PID: 4265
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chinchillapps.compare/com.chinchillapps.compare.compare}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
     at android.app.ActivityThread.access$1100(ActivityThread.java:221)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:158)
     at android.app.ActivityThread.main(ActivityThread.java:7224)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
    Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
     at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
     at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
     at com.chinchillapps.compare.compare.onCreate(compare.java:40)
     at android.app.Activity.performCreate(Activity.java:6876)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
     at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:158) 
     at android.app.ActivityThread.main(ActivityThread.java:7224) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
    Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
     at android.view.LayoutInflater.createView(LayoutInflater.java:657)
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
     at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
     at com.chinchillapps.compare.compare.onCreate(compare.java:40) 
     at android.app.Activity.performCreate(Activity.java:6876) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
     at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:158) 
     at android.app.ActivityThread.main(ActivityThread.java:7224) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
    Caused by: java.lang.reflect.InvocationTargetException
     at java.lang.reflect.Constructor.newInstance(Native Method)
     at android.view.LayoutInflater.createView(LayoutInflater.java:631)
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776) 
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) 
     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
     at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
     at com.chinchillapps.compare.compare.onCreate(compare.java:40) 
     at android.app.Activity.performCreate(Activity.java:6876) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
     at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:158) 
     at android.app.ActivityThread.main(ActivityThread.java:7224) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
    Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class com.facebook.widget.ProfilePictureView
     at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
     at android.support.design.internal.NavigationMenuPresenter.inflateHeaderView(NavigationMenuPresenter.java:211)
     at android.support.design.widget.NavigationView.inflateHeaderView(NavigationView.java:269)
     at android.support.design.widget.NavigationView.<init>(NavigationView.java:178)
     at android.support.design.widget.NavigationView.<init>(NavigationView.java:100)
     at java.lang.reflect.Constructor.newInstance(Native Method) 
     at android.view.LayoutInflater.createView(LayoutInflater.java:631) 
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776) 
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) 
     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
     at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
     at com.chinchillapps.compare.compare.onCreate(compare.java:40) 
     at android.app.Activity.performCreate(Activity.java:6876) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
     at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:158) 
     at android.app.ActivityThread.main(ActivityThread.java:7224) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
    Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class com.facebook.widget.ProfilePictureView
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
     at android.support.design.internal.NavigationMenuPresenter.inflateHeaderView(NavigationMenuPresenter.java:211) 
     at android.support.design.widget.NavigationView.inflateHeaderView(NavigationView.java:269) 
     at android.support.design.widget.NavigationView.<init>(NavigationView.java:178) 
     at android.support.design.widget.NavigationView.<init>(NavigationView.java:100) 
     at java.lang.reflect.Constructor.newInstance(Native Method) 
     at android.view.LayoutInflater.createView(LayoutInflater.java:631) 
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776) 
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) 
     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
     at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
     at com.chinchillapps.compare.compare.onCreate(compare.java:40) 
     at android.app.Activity.performCreate(Activity.java:6876) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
     at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:158) 
     at android.app.ActivityThread.main(ActivityThread.java:7224) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.widget.ProfilePictureView" on path: DexPathList[[zip file "/data/app/com.chinchillapps.compare-2/base.apk", zip file "/data/app/com.chinchillapps.compare-2/split_lib_dependencies_apk.apk", zip file "/data/

似乎错误来自于我试图在这里使用的ProfilePictureView类:

    ProfilePictureView currentUser;
    currentUser = (ProfilePictureView) findViewById(R.id.currentUser);
    currentUser.setProfileId(Profile.getCurrentProfile().getId());

我导入了这个类(我正在使用AndroidStudio) 我认为可能是错误的根源是XML,它就在这里:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
xmlns:facebook="http://schemas.android.com/tools"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark">

<com.facebook.widget.ProfilePictureView
    android:id="@+id/currentUser"
    android:layout_width="68dp"
    android:layout_height="wrap_content"
    android:paddingTop="8dp"
    android:gravity="center_horizontal"
    facebook:preset_size="small" />
<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/nav_header_vertical_spacing"
    android:text="Android Studio"
    android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="android.studio@android.com" />

</LinearLayout>

我仍然在互联网上查看错误,但我是一个伟大的Android世界的初学者,所以如果有人能帮助我,那就太棒了!

非常感谢!

1 个答案:

答案 0 :(得分:0)

在facebook sdk 4.0.1中,ProfilePictureView类不在com.facebook.widget包中。它位于com.facebook.login.widget包中。所以你的xml声明应如下所示:

<com.facebook.login.widget.ProfilePictureView
    android:id="@+id/currentUser"
    android:layout_width="68dp"
    android:layout_height="wrap_content"
    android:paddingTop="8dp"
    android:gravity="center_horizontal"
   facebook:preset_size="small"/>