Question


EDIT 1/14/2013 - I tried redownloading the facebook SDK... Still the same error.


I am getting android.view.InflateException caused by outOfMemoryException when calling facebook.authorize together with the looper.

This is a snippet of my code where the calling of facebook.authorize is being done:

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));
}

And here is the log error:

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

It worked like a charm before, but now, after adding a button (programmatically), it doesn't work anymore.

Just if it helps you to help me, here is the code where I inflate a linearlayout where I store the facebook picture and textview for the name:

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>

I hope you can help me, because I have no clue on how to proceed from here.

Était-ce utile?

La solution

I managed to get it working now! It seemed like I had too many images loaded into memory at the same time. I tried commenting out some of the big images and voila! It worked!

The solution is that you'll have to recycle the images when switching between screens where they are not needed. That way you'll save up lots of memory and not have to face the same problem as I did.

Do this when you do not need an image anymore:

    bitmap.recycle();
    bitmap = null;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top