当前位置: 首页 > 知识库问答 >
问题:

抛出OutOfMemoryError“无法分配具有15229320个可用字节和14MB的18485292字节分配,直到OOM”

那昊
2023-03-14
    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.moments.hamza.babytalk.Level_2"
    android:padding="16dp">


    <ViewFlipper
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/v_f_level2"
        android:layout_marginBottom="50dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_aid"
            android:src="@drawable/letter_a"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_bid"
            android:src="@drawable/letter_b"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_cid"
            android:src="@drawable/letter_c"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_did"
            android:src="@drawable/letter_d"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_eid"
            android:src="@drawable/letter_e"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_fid"
            android:src="@drawable/letter_f"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_gid"
            android:src="@drawable/letter_g"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_hid"
            android:src="@drawable/letter_h"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_iid"
            android:src="@drawable/letter_i"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_jid"
            android:src="@drawable/letter_j"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_kid"
            android:src="@drawable/letter_k"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_lid"
            android:src="@drawable/letter_l"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_mid"
            android:src="@drawable/letter_m"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_nid"
            android:src="@drawable/letter_n"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_oid"
            android:src="@drawable/letter_o"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_pid"
            android:src="@drawable/letter_p"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_qid"
            android:src="@drawable/letter_q"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_rid"
            android:src="@drawable/letter_r"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_sid"
            android:src="@drawable/letter_s"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_tid"
            android:src="@drawable/letter_t"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_uid"
            android:src="@drawable/letter_u"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_vid"
            android:src="@drawable/letter_v"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_wid"
            android:src="@drawable/letter_w"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_xid"
            android:src="@drawable/letter_x"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_yid"
            android:src="@drawable/letter_y"
            android:scaleType="centerCrop" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/letter_zid"
            android:src="@drawable/letter_z"
            android:scaleType="centerCrop"
            android:contentDescription="@string/a_letter" />

    </ViewFlipper>

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/next_level_2"
        android:src="@drawable/next"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true" />

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/back_level_2"
        android:src="@drawable/back"
        android:layout_alignTop="@+id/next_level_2"
        android:layout_alignParentStart="true" />

</RelativeLayout>
public class Level_2 extends AppCompatActivity {
private ImageView back_level_2;
private ImageView next_level_2;

private ImageView letteraj;
private ImageView letterbj;
private ImageView lettercj;
private ImageView letterdj;
private ImageView letterej;
private ImageView letterfj;
private ImageView lettergj;
private ImageView letterhj;
private ImageView letterij;
private ImageView letterjj;
private ImageView letterkj;
private ImageView letterlj;
private ImageView lettermj;
private ImageView letternj;
private ImageView letteroj;
private ImageView letterpj;
private ImageView letterqj;
private ImageView letterrj;
private ImageView lettersj;
private ImageView lettertj;
private ImageView letteruj;
private ImageView lettervj;
private ImageView letterwj;
private ImageView letterxj;
private ImageView letteryj;
private ImageView letterzj;

private ViewFlipper v_f_level2j;
private TextToSpeech t1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_level_2);

    v_f_level2j = (ViewFlipper) findViewById(R.id.v_f_level2);

    back_level_2 = (ImageView) findViewById(R.id.next_level_2);
    next_level_2 = (ImageView) findViewById(R.id.back_level_2);

    letteraj=(ImageView) findViewById(R.id.letter_aid);
    letterbj=(ImageView) findViewById(R.id.letter_bid);
    lettercj=(ImageView) findViewById(R.id.letter_cid);
    letterdj=(ImageView) findViewById(R.id.letter_did);
    letterej=(ImageView) findViewById(R.id.letter_eid);
    letterfj=(ImageView) findViewById(R.id.letter_fid);
    lettergj=(ImageView) findViewById(R.id.letter_gid);
    letterhj=(ImageView) findViewById(R.id.letter_hid);
    letterij=(ImageView) findViewById(R.id.letter_iid);
    letterjj=(ImageView) findViewById(R.id.letter_jid);
    letterkj=(ImageView) findViewById(R.id.letter_kid);
    letterlj=(ImageView) findViewById(R.id.letter_lid);
    lettermj=(ImageView) findViewById(R.id.letter_mid);
    letternj=(ImageView) findViewById(R.id.letter_nid);
    letteroj=(ImageView) findViewById(R.id.letter_oid);
    letterpj=(ImageView) findViewById(R.id.letter_pid);
    letterqj=(ImageView) findViewById(R.id.letter_qid);
    letterrj=(ImageView) findViewById(R.id.letter_rid);
    lettersj=(ImageView) findViewById(R.id.letter_sid);
    lettertj=(ImageView) findViewById(R.id.letter_tid);
    letteruj=(ImageView) findViewById(R.id.letter_uid);
    lettervj=(ImageView) findViewById(R.id.letter_vid);
    letterwj=(ImageView) findViewById(R.id.letter_wid);
    letterxj=(ImageView) findViewById(R.id.letter_xid);
    letteryj=(ImageView) findViewById(R.id.letter_yid);
    letterzj=(ImageView) findViewById(R.id.letter_zid);

    t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if(status != TextToSpeech.ERROR) {
                t1.setLanguage(Locale.UK);

            }
        }
    });
    letteraj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="A";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letterbj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="B";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    lettercj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="C";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letterdj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="D";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letterej.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="E";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letterfj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="F";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    lettergj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="G";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letterhj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="H";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letterij.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="I";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letterjj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="J";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letterkj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="K";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letterlj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="L";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    lettermj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="M";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letternj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="N";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letteroj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="O";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letterpj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="P";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letterqj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="Q";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letterrj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="R";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    lettersj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="S";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    lettertj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="T";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letteruj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="U";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    lettervj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="V";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letterwj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="W";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak, TextToSpeech.QUEUE_ADD, null);}});
    letterxj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="X";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letteryj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="Y";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
    letterzj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String toSpeak ="Z";
            t1.setSpeechRate((float) 1);
            t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});





    next_level_2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            v_f_level2j.showNext();
        }

    });


    back_level_2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            v_f_level2j.showPrevious();
        }

    });

}
}

你能帮帮我吗?

共有1个答案

方弘
2023-03-14

一个或多个ImageView小部件指向的资源大约为2150 x 2150像素。这个太大了。使用较小的图像。

最大大小为:28KB

这是磁盘上的大小,它没有那么有用。

 类似资料:
  • 我有这个错误在一个活动回合内存溢出: 进程:com.moments.hamza.babytalk,PID:16463java.lang.OutOfMemoryError:未能分配15230424空闲字节和14MB的18485292字节分配,直到OOM在dalvik.system.VMRuntime.newnonMovableArray(本机方法)在android.graphics.BitmapFa

  • 我想显示的位图图像从sd卡的ImageView已经存储。运行后,我的应用程序崩溃,并获得OutOfMemoryError错误:

  • 有没有办法找到Java应用程序中分配了多少字节?如果可能,在不更改代码的情况下?谢谢

  • 我试图理解DirectByteBuffer如何在Linux上工作,并编写了以下在strace下运行的非常简单的程序: 实际上,我期望一些mmap或sys\u brk系统调用直接从操作系统分配内存,但实际上它只是设置请求页面的读写保护。我的意思是: 这似乎是分配直接缓冲区比分配堆缓冲区慢的原因,因为每次分配都需要系统调用。 如果我错了,请纠正我,但是堆缓冲区分配(如果发生在TLAB内部)相当于返回一

  • 问题内容: 在下面的代码中: 为了确定从CloudFoundry接收JSON数据所需的数据类型,请测试上面的示例代码以了解vs 类型的内存分配。 类型变量的预期大小为1个字节x 4个ascii编码字母= 4个字节,但是大小显示为16个字节。 对于类型变量,GO将字符串作为字符串文字嵌入到可执行程序中。它将在运行时使用该函数将字符串文字转换为字节片。就像是… 类型变量的预期大小再次为1字节x 4 a

  • 我正在使用PHPExcel(在这里找到:https://github.com/PHPOffice/PHPExcel)。如果我尝试读取超过大约2000行,然后它显示内存错误如下。 致命错误:第89行的/home/sample/PHPExcelReader/Classes/PHPExcel/sheetwork.php中允许的134217728字节内存已耗尽(尝试分配71字节) 我的Excel数据范围是