error at setContentView - android.view.InflateException -
i have splash screen shows image 2 sec. image png image. when start app crashes following error messages. exact line app crashes setcontentview(r.layout.splash);
key error lines : see there error reference java.lang.outofmemoryerror while inflating layout
could please let tell me need correct code.
xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/splash"> </relativelayout>
java code:
public class splash extends activity{ @override protected void oncreate(bundle goonsudha) { // todo auto-generated method stub super.oncreate(goonsudha); requestwindowfeature(window.feature_no_title); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); setcontentview(r.layout.splash); thread thread = new thread(){ public void run(){ try{ sleep(2000); } catch (interruptedexception e){ e.printstacktrace(); }finally{ intent dragdropintent = new intent("android.intent.action.dragdrop"); startactivity(dragdropintent); } } }; thread.start(); } @override protected void onpause() { // todo auto-generated method stub super.onpause(); finish(); } }
logcat:
05-04 19:34:05.651: e/androidruntime(28305): fatal exception: main 05-04 19:34:05.651: e/androidruntime(28305): java.lang.runtimeexception: unable start activity componentinfo{com.example.dragdrop/com.example.dragdrop.splash}: android.view.inflateexception: binary xml file line #2: error inflating class <unknown> 05-04 19:34:05.651: e/androidruntime(28305): @ android.app.activitythread.performlaunchactivity(activitythread.java:1967) 05-04 19:34:05.651: e/androidruntime(28305): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1992) 05-04 19:34:05.651: e/androidruntime(28305): @ android.app.activitythread.access$600(activitythread.java:127) 05-04 19:34:05.651: e/androidruntime(28305): @ android.app.activitythread$h.handlemessage(activitythread.java:1158) 05-04 19:34:05.651: e/androidruntime(28305): @ android.os.handler.dispatchmessage(handler.java:99) 05-04 19:34:05.651: e/androidruntime(28305): @ android.os.looper.loop(looper.java:137) 05-04 19:34:05.651: e/androidruntime(28305): @ android.app.activitythread.main(activitythread.java:4441) 05-04 19:34:05.651: e/androidruntime(28305): @ java.lang.reflect.method.invokenative(native method) 05-04 19:34:05.651: e/androidruntime(28305): @ java.lang.reflect.method.invoke(method.java:511) 05-04 19:34:05.651: e/androidruntime(28305): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:823) 05-04 19:34:05.651: e/androidruntime(28305): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:590) 05-04 19:34:05.651: e/androidruntime(28305): @ dalvik.system.nativestart.main(native method) 05-04 19:34:05.651: e/androidruntime(28305): caused by: android.view.inflateexception: binary xml file line #2: error inflating class <unknown> 05-04 19:34:05.651: e/androidruntime(28305): @ android.view.layoutinflater.createview(layoutinflater.java:606) 05-04 19:34:05.651: e/androidruntime(28305): @ com.android.internal.policy.impl.phonelayoutinflater.oncreateview(phonelayoutinflater.java:56) 05-04 19:34:05.651: e/androidruntime(28305): @ android.view.layoutinflater.oncreateview(layoutinflater.java:653) 05-04 19:34:05.651: e/androidruntime(28305): @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:678) 05-04 19:34:05.651: e/androidruntime(28305): @ android.view.layoutinflater.inflate(layoutinflater.java:466) 05-04 19:34:05.651: e/androidruntime(28305): @ android.view.layoutinflater.inflate(layoutinflater.java:396) 05-04 19:34:05.651: e/androidruntime(28305): @ android.view.layoutinflater.inflate(layoutinflater.java:352) 05-04 19:34:05.651: e/androidruntime(28305): @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:255) 05-04 19:34:05.651: e/androidruntime(28305): @ android.app.activity.setcontentview(activity.java:1835) 05-04 19:34:05.651: e/androidruntime(28305): @ com.example.dragdrop.splash.oncreate(splash.java:18) 05-04 19:34:05.651: e/androidruntime(28305): @ android.app.activity.performcreate(activity.java:4465) 05-04 19:34:05.651: e/androidruntime(28305): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1049) 05-04 19:34:05.651: e/androidruntime(28305): @ android.app.activitythread.performlaunchactivity(activitythread.java:1931) 05-04 19:34:05.651: e/androidruntime(28305): ... 11 more 05-04 19:34:05.651: e/androidruntime(28305): caused by: java.lang.reflect.invocationtargetexception 05-04 19:34:05.651: e/androidruntime(28305): @ java.lang.reflect.constructor.constructnative(native method) 05-04 19:34:05.651: e/androidruntime(28305): @ java.lang.reflect.constructor.newinstance(constructor.java:417) 05-04 19:34:05.651: e/androidruntime(28305): @ android.view.layoutinflater.createview(layoutinflater.java:586) 05-04 19:34:05.651: e/androidruntime(28305): ... 23 more 05-04 19:34:05.651: e/androidruntime(28305): caused by: java.lang.outofmemoryerror 05-04 19:34:05.651: e/androidruntime(28305): @ android.graphics.bitmap.nativecreate(native method) 05-04 19:34:05.651: e/androidruntime(28305): @ android.graphics.bitmap.createbitmap(bitmap.java:605) 05-04 19:34:05.651: e/androidruntime(28305): @ android.graphics.bitmap.createbitmap(bitmap.java:551) 05-04 19:34:05.651: e/androidruntime(28305): @ android.graphics.bitmap.createscaledbitmap(bitmap.java:437) 05-04 19:34:05.651: e/androidruntime(28305): @ android.graphics.bitmapfactory.finishdecode(bitmapfactory.java:530) 05-04 19:34:05.651: e/androidruntime(28305): @ android.graphics.bitmapfactory.decodestream(bitmapfactory.java:505) 05-04 19:34:05.651: e/androidruntime(28305): @ android.graphics.bitmapfactory.decoderesourcestream(bitmapfactory.java:357) 05-04 19:34:05.651: e/androidruntime(28305): @ android.graphics.drawable.drawable.createfromresourcestream(drawable.java:777) 05-04 19:34:05.651: e/androidruntime(28305): @ android.content.res.resources.loaddrawable(resources.java:1940) 05-04 19:34:05.651: e/androidruntime(28305): @ android.content.res.typedarray.getdrawable(typedarray.java:601) 05-04 19:34:05.651: e/androidruntime(28305): @ android.view.view.<init>(view.java:2844) 05-04 19:34:05.651: e/androidruntime(28305): @ android.view.view.<init>(view.java:2781) 05-04 19:34:05.651: e/androidruntime(28305): @ android.view.viewgroup.<init>(viewgroup.java:412) 05-04 19:34:05.651: e/androidruntime(28305): @ android.widget.relativelayout.<init>(relativelayout.java:179) 05-04 19:34:05.651: e/androidruntime(28305): ... 26 more
your image size large. app exceeding heap size allocated app. hence outofmemoryexception. heap size varies device device.
scale down bitmap or use different image takes less memory.
you need load bitmaps efficiently. check topic under loading scaled down version in memory.
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
also load drawable layout in onresume() , unbind drawable layout in onpause().
also check video in link below
Comments
Post a Comment