Android ClassNotFound 和 android.view.InflateException:

2023-12-08

我正在尝试将 facebook 集成到我的应用程序中。我正在使用从以下位置下载的 facebook 示例应用程序facebook作为参考(还生成了appId以及所有这一切的过程开发者脸书)。我有点懒,所以我不想遍历 facebook sdk 的所有代码。简单来说,我只是添加com_android_facebook我的应用程序中的库项目,并将 facebook 示例应用程序中的所有类复制到我的应用程序中(Example.java 除外)

现在我修改MyActivity类看起来像Example.java类,意味着MyActivity现在拥有Example类的所有代码以及我的主Activity。

我将应用程序的布局更改为

    <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout

   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   xmlns:android="http://schemas.android.com/apk/res/android"
  >
  <TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:textSize="22px"
    android:textColor="#ff00ff"
    android:gravity="center"
 >
  </TextView>

<com.android.facebook.LoginButton
 android:id="@+id/login"
 android:src="@drawable/login"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentBottom="true"
/>
<Button android:id="@+id/uploadButton"
    android:text="@string/upload"
    android:visibility="invisible"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:paddingRight="20dp" 
    android:paddingLeft="20dp"
    android:layout_margin="20dp" 
    />

<Button android:id="@+id/requestButton"
    android:text="@string/request"
    android:visibility="invisible"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:paddingRight="20dp" 
    android:paddingLeft="20dp"
    android:layout_margin="20dp" 
    />


<Button android:id="@+id/postButton" 
    android:text="@string/post"
    android:visibility="invisible"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:paddingRight="20dp" 
    android:paddingLeft="20dp"
    android:layout_margin="20dp" 
    />

<Button android:id="@+id/deletePostButton" 
    android:text="@string/delete"
    android:visibility="invisible"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:paddingRight="20dp" 
    android:paddingLeft="20dp"
    android:layout_margin="20dp" 
    />

</RelativeLayout>

现在,当我运行我的应用程序时,我遇到了错误

   10-14 00:58:37.786: ERROR/AndroidRuntime(3971): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.myapp/com.android.myapp.MyActivity}: android.view.InflateException: Binary XML file line #21: Error inflating class com.android.facebook.LoginButton
   10-14 00:58:37.786: ERROR/AndroidRuntime(3971): Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class com.android.facebook.LoginButton
   10-14 00:58:37.786: ERROR/AndroidRuntime(3971): Caused by: java.lang.ClassNotFoundException: com.android.facebook.LoginButton in loader dalvik.system.PathClassLoader@44c06850

非常欢迎任何帮助、建议...


我也面临同样的问题。我将 main.xml 更改为:

<com.facebook.android.LoginButton
    android:id="@+id/login"
    android:src="@drawable/login_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:layout_margin="30dp"
    />

到(当前包是 com.facebook.fbtest_simple):

<com.facebook.fbtest_simple.LoginButton 
    android:id="@+id/login"
    android:src="@drawable/login_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:layout_margin="30dp"
    />

由于 LoginButton 不是 FB 标准库的一部分。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android ClassNotFound 和 android.view.InflateException: 的相关文章

随机推荐