我有这个错误在一个活动回合内存溢出:
进程:com.moments.hamza.babytalk,PID:16463java.lang.OutOfMemoryError:未能分配15230424空闲字节和14MB的18485292字节分配,直到OOM在dalvik.system.VMRuntime.newnonMovableArray(本机方法)在android.graphics.BitmapFactory.nativeDecodeAsset(本机方法)在android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:747)在android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:568)在android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1014)在android.content.res.Resources.loadDrawableForCookie(Resources.java:3747)在android.content.res.Resources.loadDrawable(Resources. java: 3620)在android. support. res. TyedArray. getDrawable(TyedArray. java: 762)在android. Widget. ImageView.(ImageView. java: 151)在android. Widget. ImageView.(ImageView. java: 140)在android. support. v7. Widget. AppCompatImageView.(AppCompatImageView. java: 57)在android. support. v7. Widget. AppCompatImageView.(AppCompatImageView. java: 53)在android. support. v7. app. AppCompatViewInflater. createView(AppCompatViewInflater. java: 102)在android. support. v7. app.在android. view上的LayoutInflater. flate(LayoutInflater. java: 511)。在android. view上的LayoutInflater. flate(LayoutInflater. java: 415)。在android. support. v7. app上的LayoutInflater. flate(LayoutInflater. java: 366)。在android. support. v7. app上的AppCompatDeorateIMV7. setContentView(AppCompatDeorateIMV7. java: 276)。在android. support. v7. app上的AppCompatActivity. setContentView(AppCompatActivity. java: 136)。在android. app上的Level_2。在android. app上的创建活动。在android. app上的创建活动(Activity. java: 6283)。仪器。在android. app上的创建活动(仪器。java: 1119)。ActivityThread. performLaunchActive(活动
xml布局文件:
<?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>
level_2的主要代码是:
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();
}
});
}
}
你能帮帮我吗?
您的一个或多个图像视图小部件指向的资源大约是2150 x 2150像素。这太大了。请使用较小的图像。
最大大小为:28KB
这是磁盘上的大小,没有那么大用处。
最大尺寸为660X778
然后我猜你把图像放在res/drawable/
中,然后在密度为-xxhdpi
的设备或模拟器上进行测试res/drawable/
是res/drawable mdpi/
的同义词,那里的drawable适用于中等密度屏幕。在-xxhdpi
密度环境中加载图像时,这些图像将在每个轴上按3倍的比例缩放,以保持图像的物理大小与-mdpi
设备上的图像相同。
我想显示的位图图像从sd卡的ImageView已经存储。运行后,我的应用程序崩溃,并获得OutOfMemoryError错误:
我正在我的程序中编写一个自定义内存分配器,并试图更好地理解什么是被分配的内存与未分配的内存。我被告知,对于一个基本的、“朴素的”内存分配器,对的调用必须提供与16字节对齐的大小(倍数)。这意味着,如果我需要分配5字节的内存,则应用操作(5+(16-1))&~(16-1)),在本例中,该操作最多舍入为16。如果请求的大小是17而不是5,那么它将舍入为32。 这意味着为了对齐,我们从操作系统返回的字节
有没有办法找到Java应用程序中分配了多少字节?如果可能,在不更改代码的情况下?谢谢
我试图理解DirectByteBuffer如何在Linux上工作,并编写了以下在strace下运行的非常简单的程序: 实际上,我期望一些mmap或sys\u brk系统调用直接从操作系统分配内存,但实际上它只是设置请求页面的读写保护。我的意思是: 这似乎是分配直接缓冲区比分配堆缓冲区慢的原因,因为每次分配都需要系统调用。 如果我错了,请纠正我,但是堆缓冲区分配(如果发生在TLAB内部)相当于返回一
正在显示此错误消息,有什么建议吗? php中允许的内存大小为33554432字节(尝试分配43148176字节)