我正在研究测验应用程序.这样,我在列表中显示问题和选项.我在顶部保留了一个next按钮,当单击next按钮时,我
一次又一次地调用同一页面,直到测试结束.由于某些问题由图像组成,因此我在问题下方显示一个按钮,单击该按钮时,图像将显示在新页面中.
现在,我的问题有时是当我单击按钮以显示图像时,它显示内存不足异常.
image.java
public class image extends Activity { ImageVIEw myimgvIEw; ImageVIEw buttondismiss; public static String image_url; @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.image); Intent intent = getIntent(); image_url = intent.getStringExtra(List.IMAGE_name); buttondismiss = (ImageVIEw) findVIEwByID(R.ID.dismiss1); myimgvIEw = (ImageVIEw) findVIEwByID(R.ID.imageVIEw100); int in = image_url.indexOf("."); String index = Integer.toString(in); String picturename = image_url.substring(0, in); int imageResource = getResources().getIDentifIEr(picturename,"drawable", "com.quiz.test"); // getPackagename()); myimgvIEw = (ImageVIEw) findVIEwByID(R.ID.imageVIEw100); myimgvIEw.setimageResource(imageResource); }}
Logcat:
08-18 11:11:01.063: E/AndroIDRuntime(552): FATAL EXCEPTION: main08-18 11:11:01.063: E/AndroIDRuntime(552): java.lang.OutOfMemoryError08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.graphics.BitmapFactory.nativeDecodeAsset(Native Method)08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.graphics.drawable.Drawable.createFromresourceStream(Drawable.java:773)08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.content.res.Resources.loadDrawable(Resources.java:1937)08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.content.res.Resources.getDrawable(Resources.java:664)08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.Widget.ImageVIEw.resolveUri(ImageVIEw.java:542)08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.Widget.ImageVIEw.setimageResource(ImageVIEw.java:315)08-18 11:11:01.063: E/AndroIDRuntime(552): at com.quiz.test.image.onCreate(image.java:48)08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.app.Activity.performCreate(Activity.java:4465)08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1919)08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.app.ActivityThread.access0(ActivityThread.java:122)08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.os.Handler.dispatchMessage(Handler.java:99)08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.os.Looper.loop(Looper.java:137)08-18 11:11:01.063: E/AndroIDRuntime(552): at androID.app.ActivityThread.main(ActivityThread.java:4340)08-18 11:11:01.063: E/AndroIDRuntime(552): at java.lang.reflect.Method.invokeNative(Native Method)08-18 11:11:01.063: E/AndroIDRuntime(552): at java.lang.reflect.Method.invoke(Method.java:511)08-18 11:11:01.063: E/AndroIDRuntime(552): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)08-18 11:11:01.063: E/AndroIDRuntime(552): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:551)08-18 11:11:01.063: E/AndroIDRuntime(552): at dalvik.system.NativeStart.main(Native Method)
错误显示在myimgvIEw.setimageResource(imageResource);行中.我没有得到什么问题.我在可绘制文件夹中最多保留400张图像,因为我
在我的项目中需要所有这些图像.有人请帮助我解决这个问题.我正在努力解决这个问题.任何帮助将不胜感激.
解决方法:
使用较小的图像.而已.尝试减小图像尺寸,然后再使用它.
总结以上是内存溢出为你收集整理的如何在Android中显示图片时解决“内存不足”问题?全部内容,希望文章能够帮你解决如何在Android中显示图片时解决“内存不足”问题?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)