java - app crashes when creating view (android.view.InflateException) -


public class childrenslist extends fragment   {      @nullable     @override     public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) {          view rootview = inflater.inflate(r.layout.childrens_list,container,false);         //return rootview;          imagebutton pigsbutton = (imagebutton) rootview.findviewbyid(r.id.pigsbutton);         imagebutton jackbutton = (imagebutton) rootview.findviewbyid(r.id.jacksbutton);         imagebutton hansgretbutton = (imagebutton) rootview.findviewbyid(r.id.hansgretbutton);         imagebutton mermadbutton = (imagebutton) rootview.findviewbyid(r.id.mermaidbutton);         imagebutton rapbutton = (imagebutton) rootview.findviewbyid(r.id.rapunzalbutton);         imagebutton redridbutton = (imagebutton) rootview.findviewbyid(r.id.ridingbutton);         imagebutton threebearsbutton = (imagebutton) rootview.findviewbyid(r.id.bearsbutton);         imagebutton ugduckbutton = (imagebutton) rootview.findviewbyid(r.id.duckbutton);          final mediaplayer mp = mediaplayer.create(getcontext(), r.raw.xlophone);          pigsbutton.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 intent = new intent(childrenslist.this.getactivity(),pigs_story.class);                 mp.start();                 startactivity(i);             }         });          jackbutton.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 intent = new intent(childrenslist.this.getactivity(), jack_beanstalk.class);                 mp.start();                 startactivity(i);             }         });          hansgretbutton.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 intent = new intent(childrenslist.this.getactivity(), hansel_and_gretal.class);                 mp.start();                 startactivity(i);             }         });         mermadbutton.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 intent = new intent(childrenslist.this.getactivity(), mermaid.class);                 mp.start();                 startactivity(i);             }         });         rapbutton.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 intent = new intent(childrenslist.this.getactivity(), rapunzal.class);                 mp.start();                 startactivity(i);             }         });         redridbutton.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 intent = new intent(childrenslist.this.getactivity(), redridinghood.class);                 mp.start();                 startactivity(i);             }         });         threebearsbutton.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 intent = new intent(childrenslist.this.getactivity(), threebears.class);                 mp.start();                 startactivity(i);             }         });         ugduckbutton.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 intent = new intent(childrenslist.this.getactivity(), uglyduckling.class);                 mp.start();                 startactivity(i);             }         });           return rootview; //return rootview      }  } 

i having errors appear in console , struggling how resolve them, 1 of them fatal out of memory exception there long list! shed light on , rid errors

04-19 18:47:29.392 19101-19101/com.j2d.com.bedtimestories e/androidruntime: fatal exception: main     process: com.j2d.com.bedtimestories, pid: 19101     android.view.inflateexception: binary xml file line #2: binary xml file line #2: error inflating class android.widget.scrollview         @ android.view.layoutinflater.inflate(layoutinflater.java:551)         @ android.view.layoutinflater.inflate(layoutinflater.java:429)         @ com.j2d.com.bedtimestories.childrenslist.oncreateview(childrenslist.java:25)         @ android.support.v4.app.fragment.performcreateview(fragment.java:1974)         @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1067)         @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1252)         @ android.support.v4.app.backstackrecord.run(backstackrecord.java:738)         @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1617)         @ android.support.v4.app.fragmentmanagerimpl$1.run(fragmentmanager.java:517)         @ android.os.handler.handlecallback(handler.java:739)         @ android.os.handler.dispatchmessage(handler.java:95)         @ android.os.looper.loop(looper.java:158)         @ android.app.activitythread.main(activitythread.java:7224)         @ java.lang.reflect.method.invoke(native method)         @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1230)         @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1120)      caused by: android.view.inflateexception: binary xml file line #2: error inflating class android.widget.scrollview         @ android.view.layoutinflater.createview(layoutinflater.java:657)         @ com.android.internal.policy.phonelayoutinflater.oncreateview(phonelayoutinflater.java:58)         @ android.view.layoutinflater.oncreateview(layoutinflater.java:706)         @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:774)         @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:716)         @ android.view.layoutinflater.inflate(layoutinflater.java:498)         @ android.view.layoutinflater.inflate(layoutinflater.java:429)          @ com.j2d.com.bedtimestories.childrenslist.oncreateview(childrenslist.java:25)          @ android.support.v4.app.fragment.performcreateview(fragment.java:1974)          @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1067)          @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1252)          @ android.support.v4.app.backstackrecord.run(backstackrecord.java:738)          @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1617)          @ android.support.v4.app.fragmentmanagerimpl$1.run(fragmentmanager.java:517)          @ android.os.handler.handlecallback(handler.java:739)          @ android.os.handler.dispatchmessage(handler.java:95)          @ android.os.looper.loop(looper.java:158)          @ android.app.activitythread.main(activitythread.java:7224)          @ java.lang.reflect.method.invoke(native method)          @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1230)          @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1120)       caused by: java.lang.reflect.invocationtargetexception         @ java.lang.reflect.constructor.newinstance(native method)         @ android.view.layoutinflater.createview(layoutinflater.java:631)         @ com.android.internal.policy.phonelayoutinflater.oncreateview(phonelayoutinflater.java:58)          @ android.view.layoutinflater.oncreateview(layoutinflater.java:706)          @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:774)          @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:716)          @ android.view.layoutinflater.inflate(layoutinflater.java:498)          @ android.view.layoutinflater.inflate(layoutinflater.java:429)          @ com.j2d.com.bedtimestories.childrenslist.oncreateview(childrenslist.java:25)          @ android.support.v4.app.fragment.performcreateview(fragment.java:1974)          @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1067)          @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1252)          @ android.support.v4.app.backstackrecord.run(backstackrecord.java:738)          @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1617)          @ android.support.v4.app.fragmentmanagerimpl$1.run(fragmentmanager.java:517)          @ android.os.handler.handlecallback(handler.java:739)          @ android.os.handler.dispatchmessage(handler.java:95)          @ android.os.looper.loop(looper.java:158)          @ android.app.activitythread.main(activitythread.java:7224)          @ java.lang.reflect.method.invoke(native method)          @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1230)          @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1120)       caused by: java.lang.outofmemoryerror: failed allocate 22075212 byte allocation 16777216 free bytes , 17mb until oom         @ dalvik.system.vmruntime.newnonmovablearray(native method)         @ android.graphics.bitmapfactory.nativedecodeasset(native method)         @ android.graphics.bitmapfactory.decodestream(bitmapfactory.java:856)         @ android.graphics.bitmapfactory.decoderesourcestream(bitmapfactory.java:675)         @ android.graphics.drawable.drawable.createfromresourcestream(drawable.java:2228)         @ android.content.res.resources.loaddrawableforcookie(resources.java:4211)         @ android.content.res.resources.loaddrawable(resources.java:4085)         @ android.content.res.resources.loaddrawable(resources.java:3935)         @ android.content.res.typedarray.getdrawable(typedarray.java:886)         @ android.view.view.<init>(view.java:4225)         @ android.view.viewgroup.<init>(viewgroup.java:589)         @ android.widget.framelayout.<init>(framelayout.java:97)         @ android.widget.scrollview.<init>(scrollview.java:347)         @ android.widget.scrollview.<init>(scrollview.java:343)         @ android.widget.scrollview.<init>(scrollview.java:339)         @ java.lang.reflect.constructor.newinstance(native method)          @ android.view.layoutinflater.createview(layoutinflater.java:631)          @ com.android.internal.policy.phonelayoutinflater.oncreateview(phonelayoutinflater.java:58)          @ android.view.layoutinflater.oncreateview(layoutinflater.java:706)          @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:774)          @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:716)          @ android.view.layoutinflater.inflate(layoutinflater.java:498)          @ android.view.layoutinflater.inflate(layoutinflater.java:429)          @ com.j2d.com.bedtimestories.childrenslist.oncreateview(childrenslist.java:25)          @ android.support.v4.app.fragment.performcreateview(fragment.java:1974)          @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1067)          @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1252)          @ android.support.v4.app.backstackrecord.run(backstackrecord.java:738)          @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1617)          @ android.support.v4.app.fragmentmanagerimpl$1.run(fragmentmanager.java:517)          @ android.os.handler.handlecallback(handler.java:739)          @ android.os.handler.dispatchmessage(handler.java:95)          @ android.os.looper.loop(looper.java:158)          @ android.app.activitythread.main(activitythread.java:7224)          @ java.lang.reflect.method.invoke(native method)          @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1230)          @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1120)  

the key part of error posted this:

 caused by: java.lang.outofmemoryerror: failed allocate 22075212 byte allocation 16777216 free bytes , 17mb until oom     [...]     @ android.graphics.bitmapfactory.nativedecodeasset(native method)     @ android.graphics.bitmapfactory.decodestream(bitmapfactory.java:856)     @ android.graphics.bitmapfactory.decoderesourcestream(bitmapfactory.java:675)     @ android.graphics.drawable.drawable.createfromresourcestream(drawable.java:2228)     [...]     @ android.view.layoutinflater.inflate(layoutinflater.java:429)      @ com.j2d.com.bedtimestories.childrenslist.oncreateview(childrenslist.java:25)      [...] 

this says app ran out of memory. ran out of memory while trying load image, did when childrenslist class, in oncreateview() method, called .inflate().

as else noted in comment on question, have large image file(s) in app. should scale images appropriate size avoid issue.

the android documentation has article discussing image sizes.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -