NinePatch上的IndexOutOfBoundsException

时间:2014-03-27 10:32:26

标签: android android-layout nine-patch

当我将视图的背景设置为这个特定的NinePatch图像时,我在eclipse的Graphical Layout标签中发现了这个奇怪的错误。

仅当我想要预览xhdpi或xxhdpi布局时才会出现错误。在ldpi,mdpi和hdpi上,它预览得很好。

有什么想法吗?

fragment_main.xml: Index: 0, Size: 0

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at com.android.ninepatch.NinePatchChunk.draw(NinePatchChunk.java:185)
    at com.android.ninepatch.NinePatchChunk.draw(NinePatchChunk.java:101)
    at android.graphics.NinePatch_Delegate$1.draw(NinePatch_Delegate.java:242)
    at com.android.layoutlib.bridge.impl.GcSnapshot.drawInLayer(GcSnapshot.java:613)
    at com.android.layoutlib.bridge.impl.GcSnapshot.draw(GcSnapshot.java:583)
    at android.graphics.NinePatch_Delegate.draw(NinePatch_Delegate.java:239)
    at android.graphics.NinePatch_Delegate.nativeDraw(NinePatch_Delegate.java:187)
    at android.graphics.NinePatch.nativeDraw(NinePatch.java)
    at android.graphics.NinePatch.drawSoftware(NinePatch.java:172)
    at android.graphics.Canvas.drawPatch(Canvas.java:1103)
    at android.graphics.NinePatch.draw(NinePatch.java:163)
    at android.graphics.drawable.NinePatchDrawable.draw(NinePatchDrawable.java:229)
    at android.view.View.draw(View.java:14450)
    at android.view.View.draw(View.java:14350)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
    at android.view.View.draw(View.java:14348)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
    at android.view.View.draw(View.java:14468)
    at android.view.View.draw(View.java:14350)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
    at android.view.View.draw(View.java:14468)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:584)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:338)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:332)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:504)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1584)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1309)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$ReloadListener.reloadLayoutSwt(GraphicalEditorPart.java:1817)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$ReloadListener.access$0(GraphicalEditorPart.java:1755)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$ReloadListener$1.run(GraphicalEditorPart.java:1749)
    at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
    at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3946)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3623)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1053)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:942)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)

布局代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background_landingpage_gradient" />

图像:

enter image description here

1 个答案:

答案 0 :(得分:2)

图像太高了。它一遍又一遍地重复相同的像素,即完全九个补丁。

如果它是一个渐变(从名称判断,很难用图像说),请使用XML来创建它。它看起来会更好,几乎没有存储空间。

至于原始错误,我的猜测是它的重复像素太多了。但这只是猜测。