0

编辑 1/14/2013 - 我尝试重新下载 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 名称的线性布局的代码:

爪哇:

    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>

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

4

1 回答 1

0

我现在设法让它工作!似乎我同时将太多图像加载到内存中。我试着注释掉一些大图,瞧!有效!

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

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

    bitmap.recycle();
    bitmap = null;
于 2013-01-15T07:23:20.570 回答