首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ShowCaseView内存不足错误

ShowCaseView内存不足错误
EN

Stack Overflow用户
提问于 2016-03-11 13:51:36
回答 2查看 559关注 0票数 1

我在Galaxy家族遇到了一些麻烦,展示视图在任何其他设备上都是完美无缺的,但我在Galaxy设备上得到了以下错误。

代码语言:javascript
复制
java.lang.OutOfMemoryError: Failed to allocate a 5760012 byte allocation with 3573238 free bytes and 3MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(VMRuntime.java) at android.graphics.BitmapFactory.nativeDecodeAsset(BitmapFactory.java)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:726)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:547)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1014)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:3747)
at android.content.res.Resources.loadDrawable(Resources.java:3620) at android.content.res.Resources.getDrawable(Resources.java:1852) at android.support.v4.content.res.ResourcesCompatApi21.getDrawable(ResourcesCompatApi21.java)
at android.support.v4.content.res.ResourcesCompat.getDrawable(ResourcesCompat.java)
at com.github.amlcurran.showcaseview.StandardShowcaseDrawer.(StandardShowcaseDrawer.java)
at com.github.amlcurran.showcaseview.ShowcaseView.(ShowcaseView.java)
at com.github.amlcurran.showcaseview.ShowcaseView.(ShowcaseView.java)
at com.github.amlcurran.showcaseview.ShowcaseView$Builder.(ShowcaseView.java)
at com.github.amlcurran.showcaseview.ShowcaseView$Builder.(ShowcaseView.java)
at br.com.mygas.myapplication.MainActivity.showcase(MainActivity.java)
at br.com.mygas.myapplication.MainActivity.access$300(MainActivity.java)
at br.com.mygas.myapplication.MainActivity$5.onShowcaseViewDidHide(MainActivity.java)
at com.github.amlcurran.showcaseview.ShowcaseView$2.onAnimationEnd(ShowcaseView.java)
at com.github.amlcurran.showcaseview.AnimatorAnimationFactory$2.onAnimationEnd(AnimatorAnimationFactory.java)
at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1089)
at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:666)
at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:682)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
at android.view.Choreographer.doCallbacks(Choreographer.java:590) at
android.view.Choreographer.doFrame(Choreographer.java:559) at
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
at android.os.Handler.handleCallback(Handler.java:739) at
android.os.Handler.dispatchMessage(Handler.java:95) at
android.os.Looper.loop(Looper.java:145) at
android.app.ActivityThread.main(ActivityThread.java:5942) at
java.lang.reflect.Method.invoke(Method.java) at
java.lang.reflect.Method.invoke(Method.java:372) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

这是实现的代码,它产生了上述错误:

代码语言:javascript
复制
private void showcase() {
        if (SaveSharedPreference.isMainActivity(this)) {
            switch (counter) {
                case 0:
                    new ShowcaseView.Builder(this)
                            .withMaterialShowcase()
                            .setContentTitle("Esta é a tela inicial:")
                            .setStyle(R.style.CustomShowcaseThemeNext)
                            .setShowcaseEventListener(new SimpleShowcaseEventListener() {
                                @Override
                                public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
                                    counter++;
                                    showcase();
                                }
                            })
                            .build();
                    break;

                case 1:
                    new ShowcaseView.Builder(this)
                            .setContentTitle("Selecione o tipo de combustível:")
                            .setTarget(new ViewTarget(R.id.spinner, this))
                            .setShowcaseDrawer(new CustomShowcaseView(this, findViewById(R.id.spinner).getWidth(), findViewById(R.id.spinner).getHeight()))
                            .setShowcaseEventListener(new SimpleShowcaseEventListener() {
                                @Override
                                public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
                                    counter++;
                                    showcase();
                                }
                            })
                            .build();
                    break;

                case 2:
                    new ShowcaseView.Builder(this)
                            .withMaterialShowcase()
                            .setTarget(new ViewTarget(R.id.fab2, this))
                            .setContentTitle("Clique neste botão para procurar combustível ao redor:")
                            .setStyle(R.style.CustomShowcaseThemeNext)
                            .setShowcaseEventListener(new SimpleShowcaseEventListener() {
                                @Override
                                public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
                                    counter++;
                                    showcase();
                                }
                            })
                            .build();
                    break;

                case 3:
                    new ShowcaseView.Builder(this)
                            .withMaterialShowcase()
                            .setTarget(new ViewTarget(R.id.fab2, this))
                            .setContentTitle("Lembre-se:")
                            .setContentText("É necessário estar com o GPS ligado")
                            .setStyle(R.style.CustomShowcaseTheme2)
                            .setShowcaseEventListener(new SimpleShowcaseEventListener() {
                                @Override
                                public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
                                    counter++;
                                    showcase();
                                }
                            })
                            .build();
                    SaveSharedPreference.mainActivityFirst(this);
                    break;
            }
        }
    }

我不知道这个错误是从哪里来的,所以我想找点建议。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-03-17 16:39:02

解决了将方法隐藏在ShowcaseView.java中的问题,如下所示:

代码语言:javascript
复制
@Override
    public void hide() {
        // If the type is set to one-shot, store that it has shot
        shotStateStore.storeShot();
        mEventListener.onShowcaseViewHide(this);
        fadeOutShowcase();
    }

对此:

代码语言:javascript
复制
@Override
    public void hide() {
        // If the type is set to one-shot, store that it has shot
        clearBitmap();
        shotStateStore.storeShot();
        mEventListener.onShowcaseViewHide(this);
        fadeOutShowcase();
    }
票数 0
EN

Stack Overflow用户

发布于 2016-03-12 09:12:25

OutOfMemoryError是安卓系统中最常见的问题,尤其是在处理位图时。当由于缺少内存空间而无法分配对象时,Java虚拟机(JVM)会抛出此错误,而且垃圾收集器也无法释放一些空间。

磁盘上文件的大小不一定与内存中文件的大小一致。该文件很可能被压缩,而在解码时它们不会被压缩。你需要在你的计算中说明这一点。

您可以参考如何有效地加载位图?上的本文

如何有效地加载大位图?

--虽然使用 android:largeHeap="true"不是个好主意--以下是谷歌的摘录,

然而,请求一个大堆的能力只适用于一小部分应用程序,这些应用程序可以证明需要消耗更多的RAM (如大型照片编辑应用程序)。千万不要仅仅因为内存用完而请求大堆,并且需要快速修复--只有当您确切地知道分配内存的位置和必须保留内存的原因时,才应该使用它。然而,即使你确信你的应用程序可以证明你的大堆是正确的,你也应该避免在任何可能的程度上请求它。使用额外的内存将越来越不利于整个用户体验,因为当任务切换或执行其他常见操作时,垃圾收集将花费更长的时间,而系统性能可能会更慢。

以下是文档https://developer.android.com/training/articles/memory.html的完整链接

但是,您可以尝试在andriod清单文件中设置它并运行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35941998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档