Android ClassNotFound 和 android.view.InflateException:

发布于 2024-12-09 20:53:42 字数 3303 浏览 8 评论 0原文

我正在尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

儭儭莪哋寶赑 2024-12-16 20:53:42

我也面临同样的问题。我将 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 标准库的一部分。

I also faced the same issue. I changed the main.xml from:

<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"
    />

to (Current package is 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"
    />

As LoginButton is not part of FB standard library.

耳根太软 2024-12-16 20:53:42

从 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

笑着哭最痛 2024-12-16 20:53:42

该 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)...

一个人的夜不怕黑 2024-12-16 20:53:42

简单一:

   10-14 00:58:37.786: ERROR/AndroidRuntime(3971): Caused by: java.lang.ClassNotFoundException: com.android.facebook.LoginButton in loader dalvik.system.PathClassLoader@44c06850

在 facebook src 中查找,您可以转到此 路径

AsyncFacebookRunner.java、Facebook.java、FacebookError.java、
FbDialog.java、Util.java

..并且看到没有像 LoginButton 这样的东西,那么我可以认为您正在使用旧的教程或类似的东西。

Easy one :

   10-14 00:58:37.786: ERROR/AndroidRuntime(3971): Caused by: java.lang.ClassNotFoundException: com.android.facebook.LoginButton in loader dalvik.system.PathClassLoader@44c06850

Looking for in the facebook src , you can go to this path:

AsyncFacebookRunner.java , Facebook.java, FacebookError.java ,
FbDialog.java, Util.java

..And see that there isn't nothing like LoginButton , then i can think that you are using an old tutorial or something like that.

强者自强 2024-12-16 20:53:42

初始化 Facebook SDK 对我来说很有效。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(this.getApplicationContext());
    setContentView(R.layout.activity_login);
}

Initializing the Facebook SDK is what worked for me.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(this.getApplicationContext());
    setContentView(R.layout.activity_login);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文