【发布时间】:2014-10-30 12:16:05
【问题描述】:
我有一个 xml 文件,它假设显示 15 个图像按钮,但直到 xml 文件中的图像按钮数量为 5 个或更低,它才能正常工作,但是对于更多数量的图像按钮,会引发此错误: java.lang.RuntimeException: 无法启动活动 ComponentInfo{com.example.ararat/com.example.ararat.Setwallpaper}: android.view.InflateException: Binary XML file line #35: Error inflating class
我的 xml 文件:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ImageButton android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/wall_img_1"
android:src="@drawable/wall1"
android:layout_marginBottom="5dp"/>
<ImageButton android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/wall_img_2"
android:src="@drawable/wall2"
android:layout_marginBottom="5dp"/>
<ImageButton android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/wall_img_3"
android:src="@drawable/wall3"
android:layout_marginBottom="5dp"/>
<ImageButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/wall_img_4"
android:layout_marginBottom="5dp"
android:src="@drawable/wall4"/>
<ImageButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/wall_img_5"
android:src="@drawable/wall5"
android:layout_marginBottom="5dp"/>
</LinearLayout>
</ScrollView>
注意:但是当我们添加更多(超过 5 个)具有相同图像的图像按钮(来自前 5 个图像按钮的图像,如“@drawable/wall5”)时,效果很好。
我尝试了相对布局和其他任何东西,但这个错误没有出现,我真的很困惑。
错误日志:
10-31 03:02:38.741: E/AndroidRuntime(1957): FATAL EXCEPTION: main
10-31 03:02:38.741: E/AndroidRuntime(1957): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ararat/com.example.ararat.Setwallpaper}: android.view.InflateException: Binary XML file line #36: Error inflating class <unknown>
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.app.ActivityThread.access$600(ActivityThread.java:122)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.os.Handler.dispatchMessage(Handler.java:99)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.os.Looper.loop(Looper.java:137)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.app.ActivityThread.main(ActivityThread.java:4340)
10-31 03:02:38.741: E/AndroidRuntime(1957): at java.lang.reflect.Method.invokeNative(Native Method)
10-31 03:02:38.741: E/AndroidRuntime(1957): at java.lang.reflect.Method.invoke(Method.java:511)
10-31 03:02:38.741: E/AndroidRuntime(1957): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-31 03:02:38.741: E/AndroidRuntime(1957): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-31 03:02:38.741: E/AndroidRuntime(1957): at dalvik.system.NativeStart.main(Native Method)
10-31 03:02:38.741: E/AndroidRuntime(1957): Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class <unknown>
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
10-31 03:02:38.741: E/AndroidRuntime(1957): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
10-31 03:02:38.741: E/AndroidRuntime(1957): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.app.Activity.setContentView(Activity.java:1835)
10-31 03:02:38.741: E/AndroidRuntime(1957): at com.example.ararat.Setwallpaper.onCreate(Setwallpaper.java:23)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.app.Activity.performCreate(Activity.java:4465)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
10-31 03:02:38.741: E/AndroidRuntime(1957): ... 11 more
10-31 03:02:38.741: E/AndroidRuntime(1957): Caused by: java.lang.reflect.InvocationTargetException
10-31 03:02:38.741: E/AndroidRuntime(1957): at java.lang.reflect.Constructor.constructNative(Native Method)
10-31 03:02:38.741: E/AndroidRuntime(1957): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
10-31 03:02:38.741: E/AndroidRuntime(1957): ... 25 more
10-31 03:02:38.741: E/AndroidRuntime(1957): Caused by: java.lang.OutOfMemoryError
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.content.res.Resources.loadDrawable(Resources.java:1937)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.widget.ImageView.<init>(ImageView.java:119)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.widget.ImageButton.<init>(ImageButton.java:85)
10-31 03:02:38.741: E/AndroidRuntime(1957): at android.widget.ImageButton.<init>(ImageButton.java:81)
10-31 03:02:38.741: E/AndroidRuntime(1957): ... 28 more
【问题讨论】:
-
我已经尝试使用 ic_launcher 作为 scr 到 ImageButton 的 xml,计数为 15,并且工作正常。发布您的日志
-
清理你的项目并运行
-
项目清理不能解决这个问题,它看起来我的一些图像导致了这个错误,但我所有的图像都是由 photoshop cs 创建为 jpg
-
它也可以在真实设备上运行
标签: android xml eclipse imagebutton