我正在开发一个小型Android应用程序,我正在使用Imageview将一些图像加载到应用程序
<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" />
现在,当我使用我的手机运行它时,它会崩溃应用程序并停止工作。但是当我在我的计算机模拟器上运行它时工作正常。这是什么原因
在log cat中我收到错误
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:发送信号。 PID:23317 SIG:9
答案 0 :(得分:0)
在快速搜索此问题后,我了解到以下内容:
Inflateexception很可能不是实际问题。
可能是内存不足异常。
验证图像的像素分辨率。分辨率越高,引发问题的可能性就越大。尽量将分辨率保持在最低限度。
因此,请检查像素分辨率,尝试将其弄乱到我们仍然可以看到图像的位置,但对操作的内存不会太费力。
资源: