我添加了一个 ImageView 并分配了一个 jpg 文件(a1.jpg),该文件为 770Kb。当我运行项目时,它会崩溃并显示很多错误日志。我尝试了另一个 jpg 文件,大小为 70KB 并运行该项目,这没有问题。为什么?谢谢!
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="@string/Test_string"
android:src="@drawable/a1" />
错误日志
02-09 12:47:34.692: D/AndroidRuntime(1023): Shutting down VM
02-09 12:47:34.692: W/dalvikvm(1023): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
02-09 12:47:34.802: E/AndroidRuntime(1023): FATAL EXCEPTION: main
02-09 12:47:34.802: E/AndroidRuntime(1023): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lighter.androidntest4/com.lighter.androidntest4.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.os.Handler.dispatchMessage(Handler.java:99)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.os.Looper.loop(Looper.java:137)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-09 12:47:34.802: E/AndroidRuntime(1023): at java.lang.reflect.Method.invokeNative(Native Method)
02-09 12:47:34.802: E/AndroidRuntime(1023): at java.lang.reflect.Method.invoke(Method.java:511)
02-09 12:47:34.802: E/AndroidRuntime(1023): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-09 12:47:34.802: E/AndroidRuntime(1023): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-09 12:47:34.802: E/AndroidRuntime(1023): at dalvik.system.NativeStart.main(Native Method)
02-09 12:47:34.802: E/AndroidRuntime(1023): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
02-09 12:47:34.802: E/AndroidRuntime(1023): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-09 12:47:34.802: E/AndroidRuntime(1023): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.Activity.setContentView(Activity.java:1881)
02-09 12:47:34.802: E/AndroidRuntime(1023): at com.lighter.androidntest4.MainActivity.onCreate(MainActivity.java:15)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.Activity.performCreate(Activity.java:5104)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-09 12:47:34.802: E/AndroidRuntime(1023): ... 11 more
02-09 12:47:34.802: E/AndroidRuntime(1023): Caused by: java.lang.reflect.InvocationTargetException
02-09 12:47:34.802: E/AndroidRuntime(1023): at java.lang.reflect.Constructor.constructNative(Native Method)
02-09 12:47:34.802: E/AndroidRuntime(1023): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
02-09 12:47:34.802: E/AndroidRuntime(1023): ... 24 more
02-09 12:47:34.802: E/AndroidRuntime(1023): Caused by: java.lang.OutOfMemoryError
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.content.res.Resources.loadDrawable(Resources.java:1965)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.widget.ImageView.<init>(ImageView.java:120)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.widget.ImageView.<init>(ImageView.java:110)
02-09 12:47:34.802: E/AndroidRuntime(1023): ... 27 more