0
I’m in trouble because I’m creating 1 app and running a good one on the emulator. And when I run on cellular of this error below...
Note: in the cell it opens and closes.
Obs2: in the emulator runs perfectly.
FATAL EXCEPTION: main
Process: com.example.dutra_pc.navigation_teste, PID: 21972
java.lang.OutOfMemoryError: Failed to allocate a 4981212 byte allocation with 3804820 free bytes and 3MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:988)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2477)
at android.content.res.Resources.loadDrawable(Resources.java:2384)
at android.content.res.Resources.getDrawable(Resources.java:787)
at android.content.Context.getDrawable(Context.java:403)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:351)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:200)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:85)
at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:94)
at com.example.dutra_pc.navigation_teste.ButaoAdapter.getView(ButaoAdapter.java:35)
at android.widget.AbsListView.obtainView(AbsListView.java:2347)
at android.widget.ListView.makeAndAddView(ListView.java:1864)
at android.widget.ListView.fillDown(ListView.java:698)
at android.widget.ListView.fillFromTop(ListView.java:759)
at android.widget.ListView.layoutChildren(ListView.java:1673)
at android.widget.AbsListView.onLayout(AbsListView.java:2151)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1196)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2116)
at android.
package com.example.dutra_pc.navigation_teste;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
public class Main2Activity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
if(savedInstanceState == null){
getSupportFragmentManager()
.beginTransaction()
.add(R.id.content_ini, new Content_Ini())
.commit();
}
ListView lista = (ListView) findViewById(R.id.lista);
final ArrayList<Butao>butaos = adicionar();
final ArrayAdapter adapter = new ButaoAdapter(this,butaos);
lista.setAdapter(adapter);
lista.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
Butao butao = (Butao) adapter.getItem(position);
Toast.makeText(Main2Activity.this,butao.getNome(), Toast.LENGTH_SHORT).show();
if(position ==0){
//LayoutInflater inflater = LayoutInflater.from(view.getContext());
/*if(savedInstanceState == null){
getSupportFragmentManager()
.beginTransaction()
.add(R.id.cosProg, new Frag_Ini())
.commit();
Comando para iniciar fragments
}*/
//Intent myIntent = new Intent(view.getContext(), Main3Activity.class);
//startActivityForResult(myIntent, 0);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_ini, new Comunicacao()).commit();
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
}else if (position ==1 ){
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_ini, new Programacao()).commit();
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
}
}
});
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
private ArrayList<Butao>adicionar(){
ArrayList<Butao>butaos = new ArrayList<>();
Butao a = new Butao("Comunicação", R.drawable.comunicacao);
butaos.add(a);
Butao b = new Butao("Programação", R.drawable.programacao);
butaos.add(b);
Butao c = new Butao("Eventos", R.drawable.eventos);
butaos.add(c);
Butao d = new Butao("Caravanas", R.drawable.caravanas);
butaos.add(d);
Butao e = new Butao("Experiência de fé", R.drawable.experiencia);
butaos.add(e);
Butao f = new Butao("Cultos", R.drawable.cultos);
butaos.add(f);
Butao g = new Butao("Aniversários", R.drawable.aniversarios);
butaos.add(g);
Butao h = new Butao("Secretaria", R.drawable.secretaria);
butaos.add(h);
Butao i = new Butao("Formação Jovem", R.drawable.formacao_jovens);
butaos.add(i);
Butao j = new Butao("Contato", R.drawable.contato);
butaos.add(j);
Butao k = new Butao("Compartilhar", R.drawable.ic_menu_share);
butaos.add(k);
return butaos;
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main2, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
//ArrayList<Butao>butaos = new ArrayList<>();
ArrayList<Butao>butaos = adicionar();
ArrayAdapter adapter = new ButaoAdapter(this,butaos);
int id = item.getGroupId();
if (id == R.id.textView1) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
The app needs
4981212
memory, but only has3804820
available-space.– NoobSaibot
@wmsouza cellular has 8Gb of memory if it helps this information for something...
– Thales Monteiro
It would be interesting to share the code with us! When I speak from memory, I speak from the library OOM who tried to allocate more memory than available at that time. Put in your file manifest on the tag
application
that:android:hardwareAccelerated="false", android:largeHeap="true"
– NoobSaibot
@wmsouza q part of the code ?
– Thales Monteiro
Thank you very much! you are the Guy! hahaha worked! has how to explain what was done ? @wmsouza ?
– Thales Monteiro
Dude, is there a heavy image in your app (on his screens)? Because if so, it’s usually this... Images of 2MB, 1.5MB usually cause this kind of problem.
– itscorey
@itscorey no image comes to that all n they are in KB
– Thales Monteiro