gpt4 book ai didi

java - 显示幻灯片 - Android OutOfMemoryError

转载 作者:行者123 更新时间:2023-12-02 01:26:58 24 4
gpt4 key购买 nike

我正在尝试显示超过 50 张图像的幻灯片。每当我运行它时,我都会收到 OutOfMemoryError 错误。我的代码是:

public class SlideshowActivity extends Activity {

private ViewFlipper myViewFlipper;
int[] image = { R.drawable.one_facebook, R.drawable.two_facebook,
R.drawable.three_facebook, R.drawable.four_facebook, R.drawable.five_facebook,
R.drawable.six_facebook, R.drawable.seven_facebook, R.drawable.eight_facebook,
R.drawable.nine_facebook, R.drawable.ten_facebook, R.drawable.eleven_facebook,
R.drawable.onetwo_facebook, etc. };

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_slideshow);
myViewFlipper = (ViewFlipper) findViewById(R.id.myflipper);

for (int i = 0; i < image.length; i++) {
ImageView imageView = new ImageView(SlideshowActivity.this);
imageView.setImageResource(image[i]);
myViewFlipper.addView(imageView);

}
myViewFlipper.setAutoStart(true);
myViewFlipper.setFlipInterval(1000);
myViewFlipper.startFlipping();
}

我的 logcat 显示:

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.applications.codegeek.slideshow, PID: 10126 java.lang.OutOfMemoryError: Failed to allocate a 52920012 byte allocation with 4194304 free bytes and 31MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:620) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:455) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1155) at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:720) at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571) at android.content.res.Resources.getDrawable(Resources.java:771) at android.content.Context.getDrawable(Context.java:525) at android.widget.ImageView.resolveUri(ImageView.java:856) at android.widget.ImageView.setImageResource(ImageView.java:448) at com.applications.codegeek.slideshow.SlideshowActivity$override.onCreate(SlideshowActivity.java:29) at com.applications.codegeek.slideshow.SlideshowActivity$override.access$dispatch(SlideshowActivity.java) at com.applications.codegeek.slideshow.SlideshowActivity.onCreate(SlideshowActivity.java:0) at android.app.Activity.performCreate(Activity.java:6679) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4519) at android.app.ActivityThread.-wrap19(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1483) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

如有任何帮助,我们将不胜感激!谢谢!

最佳答案

为了减少内存,您可以使用此插件 Android Drawable Importer Plugin

还有..

list 中的 android:largeHeap="true"它将增加你的堆大小并避免内存不足

祝你好运!

关于java - 显示幻灯片 - Android OutOfMemoryError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41782950/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com