调用facebook.authorize时,android.view.InflateException

时间:2013-01-14 19:42:31

标签: android facebook exception inflate-exception


编辑2013年1月14日 - 我尝试重新下载facebook SDK ...仍然是同样的错误。


当与looper一起调用facebook.authorize时,我收到了由outOfMemoryException引起的android.view.InflateException。

这是我的代码片段,其中正在调用facebook.authorize:

public void promptLogin(){
    if (! facebook.isSessionValid()) {
        loginAndContinue();
    }
    else {
        Continue();
    }
}
public void loginAndContinue(){
    new Thread(new Runnable() {

        public void run() {
            // TODO Auto-generated method stub
            Looper.prepare();
            openLoginDialog();
            Looper.loop(); // This is line 248
        }
    }).start();
}
public void openLoginDialog(){
    facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
}
public void Continue(){
    AsyncFacebookRunner myAsyncRunner = new AsyncFacebookRunner(facebook);
    myAsyncRunner.request("me", new meRequestListener(this));
}

以下是日志错误:

>     01-14 19:42:04.551: E/AndroidRuntime(890): FATAL EXCEPTION: Thread-105
>     01-14 19:42:04.551: E/AndroidRuntime(890): android.view.InflateException: Binary XML file line #107: Error
> inflating class <unknown>
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.view.LayoutInflater.createView(LayoutInflater.java:606)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at com.android.internal.app.AlertController.installContent(AlertController.java:240)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.app.AlertDialog.onCreate(AlertDialog.java:336)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.app.ProgressDialog.onCreate(ProgressDialog.java:198)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.app.Dialog.dispatchOnCreate(Dialog.java:353)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.app.Dialog.show(Dialog.java:257)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at com.facebook.widget.WebDialog$DialogWebViewClient.onPageStarted(WebDialog.java:364)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:267)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.os.Handler.dispatchMessage(Handler.java:99)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.os.Looper.loop(Looper.java:137)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at com.COMPANYNAME.framework.impl.AndroidGame$6.run(AndroidGame.java:248)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at java.lang.Thread.run(Thread.java:856)
>     01-14 19:42:04.551: E/AndroidRuntime(890): Caused by: java.lang.reflect.InvocationTargetException
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at java.lang.reflect.Constructor.constructNative(Native Method)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.view.LayoutInflater.createView(LayoutInflater.java:586)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    ... 20 more
>     01-14 19:42:04.551: E/AndroidRuntime(890): Caused by: java.lang.OutOfMemoryError
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.content.res.Resources.loadDrawable(Resources.java:1935)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.view.View.<init>(View.java:2785)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.view.ViewGroup.<init>(ViewGroup.java:385)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.widget.LinearLayout.<init>(LinearLayout.java:174)
>     01-14 19:42:04.551: E/AndroidRuntime(890):    at android.widget.LinearLayout.<init>(LinearLayout.java:170)

它以前就像魅力一样,但现在,在添加按钮(以编程方式)后,它不再起作用了。

如果它可以帮助你帮助我,这里是我为了名称存储facebook图片和textview的线性布局的代码:

JAVA:

    setContentView(gameLayout);
    View.inflate(this, R.layout.facebook, gameLayout);
    facebookLayout = (LinearLayout)findViewById(R.id.facebookLayout);
    facebookName = (TextView)findViewById(R.id.facebookName);
    profilePicture = (ProfilePictureView)findViewById(R.id.profile_pic);
    profilePicture.setCropped(true);
    getNameAndId();
    facebookName.setText("Welcome, " + name + "!");
    showFacebook(false);
    checkState();
}

public void checkState() {
    if (! facebook.isSessionValid()) {
        facebookName.setVisibility(View.GONE);
        profilePicture.setVisibility(View.GONE);
    }
}

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:facebook="http://schemas.android.com/apk/res-auto"
    android:id="@+id/facebookLayout"
    android:orientation="vertical"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:layout_gravity="center"
    android:padding="100dp"
    android:layout_alignParentTop="true">
    <com.facebook.widget.ProfilePictureView
        android:id="@+id/profile_pic"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_gravity="center"
        android:gravity="center_horizontal"
        facebook:preset_size="small" />
    <TextView android:id="@+id/facebookName"
        android:text="Welcome!"
        android:textColor="#0000FF"
        android:padding="5dp"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:gravity="center"/>
</LinearLayout>

我希望你能帮助我,因为我不知道如何从这里开始。

1 个答案:

答案 0 :(得分:0)

我设法让它现在正常运作!好像我有太多的图像同时加载到内存中。我试着评论一些大图像和瞧!它奏效了!

解决方案是,在不需要它们的屏幕之间切换时,您必须回收图像。这样你就可以节省大量内存,而不必像我一样面对同样的问题。

当您不再需要图片时执行此操作:

    bitmap.recycle();
    bitmap = null;