Android ClassNotFound 和 android.view.InflateException:
我正在尝试将 facebook 集成到我的应用程序中。我正在使用从 facebook 作为参考(还生成了 appId
以及 developer.facebook 上的所有此过程) .我有点懒,所以我不想经历所有的事情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
任何帮助,建议是最受欢迎的......
I m trying to integrate the facebook in my app.I am using facebook example app downloaded from facebook as a reference(also generated the appId
and all this process on developer.facebook).I am little lazy so I do not want to go through all the code of facebook sdk.In simple words i just add the com_android_facebook
library project in my app, and also copy all the classes in facebook example app in my app except Example.java
Now i modify the MyActivity class look like Example.java class, means MyActivity now have all the code of Example class and also my main Activity.
and i change the layout of my app as
<?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>
Now when i run my app i am getting there errors
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
Any help, suggestions are most welcome...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我也面临同样的问题。我将 main.xml 从: 更改
为(当前包是 com.facebook.fbtest_simple):
因为 LoginButton 不是 FB 标准库的一部分。
I also faced the same issue. I changed the main.xml from:
to (Current package is com.facebook.fbtest_simple):
As LoginButton is not part of FB standard library.
从 Facebook SDK 3.0 版开始,LoginButton 现在作为 SDK 的一部分提供:
com.facebook.widget.LoginButton
请参阅 https://developers.facebook.com/docs /reference/android/3.0/LoginButton
注意Facebook自己的升级说明此处引用了错误的包,LoginButton必须声明为 com.facebook.widget.LoginButton,而不是 com.facebook.LoginButton
As of version 3.0 of the Facebook SDK, the LoginButton is now available as part of the SDK as
com.facebook.widget.LoginButton
See https://developers.facebook.com/docs/reference/android/3.0/LoginButton
Note that Facebook's own upgrade instructions here reference the wrong package, the LoginButton must be declared as com.facebook.widget.LoginButton, not com.facebook.LoginButton
该 SDK 的主要源代码中没有
LoginButton
。它仅在示例代码中可用,因此它只是无法加载不可用的类(
ClassNotFoundException
)...There is no
LoginButton
in the main source of that SDK.It's available in the sample code only, so it just fails to load the unavailable class (
ClassNotFoundException
)...简单一:
在 facebook src 中查找,您可以转到此 路径:
..并且看到没有像 LoginButton 这样的东西,那么我可以认为您正在使用旧的教程或类似的东西。
Easy one :
Looking for in the facebook src , you can go to this path:
..And see that there isn't nothing like LoginButton , then i can think that you are using an old tutorial or something like that.
初始化 Facebook SDK 对我来说很有效。
Initializing the Facebook SDK is what worked for me.