【问题标题】:Android Eclipse Layout doesn't seen on SDK 8在 SDK 8 上看不到 Android Eclipse 布局
【发布时间】:2012-12-11 11:38:55
【问题描述】:

我在 TARGET SDK:17 和 MİN SDK:8 上做了一个布局。还可以。当它在 SDK:17 上时,但是当我用 SDK:8 尝试它时,它在底部给出了错误。谁能告诉我如何让我的代码在 SDK:8 上运行谢谢你的帮助。 这是 XML ....

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:ignore="UselessParent" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <TextView
                android:id="@+id/textButtonBakici"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/textBakici" />

            <EditText
                android:id="@+id/editTextBakici"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="3"
                android:layout_weight="1"
                android:hint="@string/altiyuzyirmibes"
                android:inputType="numberDecimal" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textKrediAraba"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/textKrediAraba"/>

            <EditText
                android:id="@+id/editTextKrediAraba"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="3"
                android:layout_weight="1"
                android:hint="@string/besyuzdoksan"
                android:inputType="numberDecimal" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textOgrenimKredisi"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/textOgrenimKredisi" />

            <EditText
                android:id="@+id/editTextOgrenimKredisi"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="3"
                android:layout_weight="1"
                android:hint="@string/dortyuzon"
                android:inputType="numberDecimal" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textTatilKredisi"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/textTatilKredisi"/>

            <EditText
                android:id="@+id/editTextTatilKredisi"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="3"
                android:layout_weight="1"
                android:hint="@string/yuzotuzbes"
                android:inputType="numberDecimal" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow5"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <TextView
                android:id="@+id/textFaturaElektrik"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/textFaturaElektrik" />

            <EditText
                android:id="@+id/editTextFaturaElektrik"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="3"
                android:layout_weight="1"
                android:hint="@string/sifir"
                android:inputType="numberDecimal" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow6"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <TextView
                android:id="@+id/textFaturaSu"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/textFaturaSu" />

            <EditText
                android:id="@+id/editTextFaturaSu"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="3"
                android:layout_weight="1"
                android:hint="@string/sifir"
                android:inputType="numberDecimal" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow7"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <TextView
                android:id="@+id/textFaturaInternet"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/textFaturaInternet" />

            <EditText
                android:id="@+id/editTextFaturaInternet"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="3"
                android:layout_weight="1"
                android:hint="@string/otuz"
                android:inputType="numberDecimal" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow8"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <TextView
                android:id="@+id/textAidat"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/textAidat"/>

            <EditText
                android:id="@+id/editTextAidat"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="3"
                android:layout_weight="1"
                android:hint="@string/sifir"
                android:inputType="numberDecimal" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow9"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <TextView
                android:id="@+id/textKaskoSigorta"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/textKaskoSigorta" />

            <EditText
                android:id="@+id/editTextKaskoSigorta"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="3"
                android:layout_weight="1"
                android:ems="10"
                android:hint="@string/ikiyuzyirmibes"
                android:inputType="numberDecimal" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow10"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="10"
                android:orientation="horizontal" >

                <Spinner
                    android:id="@+id/spinnerYillar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:entries="@array/Yillar"
                    android:prompt="@string/promptYillar" />

                <Spinner
                    android:id="@+id/spinnerAylar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:entries="@array/Aylar"
                    android:prompt="@string/prompt" />
            </LinearLayout>

            <Button
                android:id="@+id/buttonIleri"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_weight="0"
                android:background="@drawable/navigation_forward"
                android:gravity="right" />
        </TableRow>
    </TableLayout>

</LinearLayout>

这是错误日志:

!ENTRY com.android.ide.eclipse.adt 4 0 2012-12-25 16:41:18.827
!MESSAGE butcegiris.xml: Index: 1, Size: 1
!STACK 0
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
    at java.util.ArrayList.rangeCheck(Unknown Source)
    at java.util.ArrayList.get(Unknown Source)
    at com.android.ninepatch.NinePatchChunk.draw(NinePatchChunk.java:174)
    at com.android.ninepatch.NinePatchChunk.draw(NinePatchChunk.java:101)
    at android.graphics.NinePatch_Delegate$1.draw(NinePatch_Delegate.java:219)
    at com.android.layoutlib.bridge.impl.GcSnapshot.drawInLayer(GcSnapshot.java:608)
    at com.android.layoutlib.bridge.impl.GcSnapshot.draw(GcSnapshot.java:577)
    at android.graphics.NinePatch_Delegate.draw(NinePatch_Delegate.java:217)
    at android.graphics.NinePatch_Delegate.nativeDraw(NinePatch_Delegate.java:170)
    at android.graphics.NinePatch.nativeDraw(NinePatch.java)
    at android.graphics.NinePatch.draw(NinePatch.java:104)
    at android.graphics.drawable.NinePatchDrawable.draw(NinePatchDrawable.java:188)
    at android.view.View.draw(View.java:6725)
    at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
    at android.view.View.draw(View.java:6743)
    at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
    at android.view.View.draw(View.java:6743)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:466)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:320)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:325)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:440)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1545)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1302)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.changed(GraphicalEditorPart.java:718)
    at com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationChooser.setConfiguration(ConfigurationChooser.java:632)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderPreviewManager.switchTo(RenderPreviewManager.java:1352)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderPreview.click(RenderPreview.java:837)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderPreviewManager.click(RenderPreviewManager.java:1494)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GestureManager$Listener.mouseUp(GestureManager.java:469)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:219)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
    at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
    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:344)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1410)

!ENTRY com.android.ide.eclipse.adt 4 0 2012-12-25 16:41:18.991
!MESSAGE butcegiris.xml: Index: 1, Size: 1
!STACK 0
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1

【问题讨论】:

  • 错误日志真的来自安卓设备吗?它看起来更像是 Eclipse 的崩溃日志....?
  • @Matthieu 不,它不是来自安卓设备。它来自 Eclipse 错误日志。
  • 我明白了...当您在运行 SDK 8 (Froyo) 的模拟器上运行代码时会发生什么? (我自己不使用 Eclipse,所以不确定我能帮到你多少)

标签: android xml eclipse layout eclipse-adt


【解决方案1】:

问题不在于 SDK 版本或目标版本。问题在于您在某处使用了arraylist,并且那里的索引映射错误。

日志猫清楚地显示:索引为1,大小为1

这意味着您的索引超出了数组列表/数组的大小。

你能不能把活动代码分享给我或者自己检查一下大小问题

谢谢

【讨论】:

    【解决方案2】:

    根据我的经验和我在 google io 视频上听到的内容,您应该始终为您的应用使用最新的 SDK,包括 ui 设计器。

    原因是 google 仅(或大部分)更新设计器的最新 sdk 目标,因此与以前的版本相比,错误更少。

    另外,请注意,即使是现在,与真实设备(甚至模拟器)上发生的事情相比,您也不能完全信任 ui 设计器。很多时候它不能很好地显示某些东西(或根本无法显示),因为它还不受支持(例如文本阴影、部分圆角的图像角......)。

    所以,简而言之,总是将 targetSdk 设置为最新的(minSdk 应该是你想要的任何东西),包括 ui 设计器,如果你想在旧版本上检查它,请尝试使用模拟器(或真实设备)以防万一。

    【讨论】:

      【解决方案3】:

      这不是你的代码错误,而是android sdk渲染库中的一个众所周知的错误。

      参考:bug in android rendering layout

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-05-05
        • 1970-01-01
        • 2020-11-26
        • 2014-12-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多