简体   繁体   中英

unfortunately app has stopped in android emulator when imageview loaded

i am developing a small android application and i am using Imageview to load some images to the application

 <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageView"
            android:src="@drawable/starr"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginRight="10dp"

            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Ishan ayesha"
            android:id="@+id/textView5"
            android:layout_alignTop="@+id/imageView"
            android:layout_toRightOf="@+id/imageView"
            android:layout_toEndOf="@+id/imageView" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="Small TextSmall TextSmall TextSmall TextSmall TextSmall TextSmall Text"
            android:id="@+id/textView6"
            android:layout_below="@+id/textView5"
            android:layout_toRightOf="@+id/imageView"
            android:layout_toEndOf="@+id/imageView" />

now when i run this using my phone it crashes the app and stopping working.But when i run this on my computer simulator it works fine.what is the reason for this

in the log cat i am getting error

03-12 01:38:07.250 23317-23317/com.example.pavithraprabodha.selfimania E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                     Process: com.example.pavithraprabodha.selfimania, PID: 23317
                                                                                     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pavithraprabodha.selfimania/com.example.pavithraprabodha.selfimania.MainActivity}: android.view.InflateException: Binary XML file line #28: Error inflating class ImageView
                                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2319)
                                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2370)
                                                                                         at android.app.ActivityThread.access$800(ActivityThread.java:155)
                                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                         at android.os.Looper.loop(Looper.java:136)
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:5426)
                                                                                         at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                         at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
                                                                                         at dalvik.system.NativeStart.main(Native Method)
                                                                                      Caused by: android.view.InflateException: Binary XML file line #28: Error inflating class ImageView
                                                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:720)
                                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:762)
                                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:771)
                                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:771)
                                                                                         at android.view.LayoutInflater.parseInclude(LayoutInflater.java:858)
                                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
                                                                                         at android.view.LayoutInflater.parseInclude(LayoutInflater.java:858)
                                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
                                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
                                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
                                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
                                                                                         at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
                                                                                         at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
                                                                                         at com.example.pavithraprabodha.selfimania.MainActivity.onCreate(MainActivity.java:34)
                                                                                         at android.app.Activity.performCreate(Activity.java:5296)
                                                                                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
                                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2283)
                                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2370) 
                                                                                         at android.app.ActivityThread.access$800(ActivityThread.java:155) 
                                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243) 
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                         at android.os.Looper.loop(Looper.java:136) 
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:5426) 
                                                                                         at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                         at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 
                                                                                         at dalvik.system.NativeStart.main(Native Method) 
                                                                                      Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f020057 a=-1 r=0x7f020057}
                                                                                         at android.content.res.Resources.loadDrawable(Resources.java:3420)
                                                                                         at android.content.res.TypedArray.getDrawable(TypedArray.java:603)
                                                                                         at android.widget.ImageView.<init>(ImageView.java:134)
                                                                                         at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:57)
                                                                                         at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53)
                                                                                         at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
                                                                                         at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:963)
                                                                                         at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1022)
                                                                                         at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
                                                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
                                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:762) 
                                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:771) 
                                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:771) 
                                                                                         at android.view.LayoutInflater.parseInclude(LayoutInflater.java:858) 
                                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:752) 
                                                                                         at android.view.LayoutInflater.parseInclude(LayoutInflater.java:858) 
                                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:752) 
                                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:499) 
                                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
                                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
                                                                                         at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267) 
                                                                                         at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129) 
                                                                                         at com.example.pavithraprabodha.selfimania.MainActivity.onCreate(MainActivity.java:34) 
                                                                                         at android.app.Activity.performCreate(Activity.java:5296) 
                                                                                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 
                                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2283) 
                                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2370) 
                                                                                         at android.app.ActivityThread.access$800(ActivityThread.java:155) 
                                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243) 
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                         at android.os.Looper.loop(Looper.java:136) 
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:5426) 
                                                                                         at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                         at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 
                                                                                         at dalvik.system.NativeStart.main(Native Method) 

03-12 01:38:27.780 23317-23317/com.example.pavithraprabodha.selfimania I/Process: Sending signal. PID: 23317 SIG: 9

After a quick search on this issue, I learned the following:

  • Inflateexception is most likely not the actual problem.

  • It could be an out of memory exception.

  • Verify the pixel resolution for your images. The higher the resolution, the more likely it is to cause a problem. Try to keep the resolution at the minimum.

So check the pixel resolution, try messing around with it to a point where we can still see the image but isn't too taxing on the memory for operations.

Resource:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM