gpt4 book ai didi

java - Android Java Switch 语句失败 - 堆大小?

转载 作者:行者123 更新时间:2023-12-02 05:13:00 26 4
gpt4 key购买 nike

我已经在 android studio 中编写了这个 switch 语句,但是每当模拟器运行时它就会崩溃,因为它说设备内存不足。每个图像只有 20kb,但我想我需要增加“堆”大小或其他名称?抱歉,我是安卓新手。我将包含在下面的调试器中显示的 switch 语句和错误消息。提前感谢您的帮助:)

Java Switch 语句

    rating = 5;

switch(rating){
case 0:
ratingBar.setImageResource(R.drawable.star0);
break;

case 1:
ratingBar.setImageResource(R.drawable.star05);
break;

case 2:
ratingBar.setImageResource(R.drawable.star1);
break;

case 3:
ratingBar.setImageResource(R.drawable.star15);
break;
case 4:
ratingBar.setImageResource(R.drawable.star2);
break;
case 5:
ratingBar.setImageResource(R.drawable.star25);
break;
case 6:
ratingBar.setImageResource(R.drawable.star3);
break;
case 7:
ratingBar.setImageResource(R.drawable.star35);
break;
case 8:
ratingBar.setImageResource(R.drawable.star4);
break;
case 9:
ratingBar.setImageResource(R.drawable.star45);
break;
case 10:
ratingBar.setImageResource(R.drawable.star5);
break;
}

调试器错误消息

1504-1504/com.cs13ppz.virtualgallery E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.cs13ppz.virtualgallery, PID: 1504
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
at android.content.res.Resources.loadDrawable(Resources.java:2110)
at android.content.res.Resources.getDrawable(Resources.java:700)
at android.widget.ImageView.resolveUri(ImageView.java:638)
at android.widget.ImageView.setImageResource(ImageView.java:367)
at com.cs13ppz.virtualgallery.ArtworkLibrary.onCreate(ArtworkLibrary.java:41)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)

最佳答案

还可以尝试通过编辑模拟器来增加模拟器内存​​。 Device Edit

关于java - Android Java Switch 语句失败 - 堆大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27196321/

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