Android 4.0.1 - XML Rendering Error in EditText. Index:0, Size: 0 - Vew draw failed

两盒软妹~` 提交于 2021-01-29 13:52:09

问题


I am having an issue while adding the EditText in my Activity's XML. It's not visible correctly and when I run App it's there but by clicking on it the keyboard does not show I am unable to add any input there. First, I thought I was having this issue only in this Activity but when I tried to add EditText in any other Activity of the project this same thing is happening, but the EditText's that have been added before I have updated to the new version of Android studio 4.0.1 is working fine in XML and also when I run the app - keyboards show up and I can add input, using compileSdkVersion 29 minSdkVersion 18 targetSdkVersion 29 this is my XML. for edit text in this Activity.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="horizontal"
    android:background="@drawable/square_border">

    <EditText
        android:id="@+id/idOrderSummaryPostcode"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:hint="Enter Postcode"
        android:padding="5dp"
        android:textSize="18sp"
        android:layout_weight="1" />

    <Button
        android:id="@+id/idOrderSummaryPostcodeAddNew"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:text="+ New"
        android:textAllCaps="false"
        android:textSize="15sp"
        android:background="@drawable/border_style_round_light_gray_solid"/>

</LinearLayout>

here's my Activity in Manifest

<activity
        android:name=".view.Order.Checkout"
        android:screenOrientation="portrait" />

I have initialized it in the onCreate like this

private EditText postcode;

postcode = findViewById(R.id.idOrderSummaryPostcode);

I am getting this error in my XML Design window.

index: 0, size:0
view draw detail(Details)

when I click the (Details) here are the details of this error.

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:657)
at java.util.ArrayList.get(ArrayList.java:433)
at com.android.ninepatch.NinePatchChunk.draw(NinePatchChunk.java:190)
at com.android.ninepatch.NinePatchChunk.draw(NinePatchChunk.java:106)
at android.graphics.BaseCanvas_Delegate$1.draw(BaseCanvas_Delegate.java:464)
at com.android.layoutlib.bridge.impl.GcSnapshot.drawInLayer(GcSnapshot.java:697)
at com.android.layoutlib.bridge.impl.GcSnapshot.draw(GcSnapshot.java:587)
at android.graphics.BaseCanvas_Delegate.nDrawNinePatch(BaseCanvas_Delegate.java:461)
at android.graphics.BaseCanvas.nDrawNinePatch(BaseCanvas.java)
at android.graphics.BaseCanvas.drawPatch(BaseCanvas.java:307)
at android.graphics.Canvas.drawPatch(Canvas.java:1825)
at android.graphics.NinePatch.draw(NinePatch.java:217)
at android.graphics.drawable.NinePatchDrawable.draw(NinePatchDrawable.java:249)
at android.graphics.drawable.DrawableContainer.draw(DrawableContainer.java:87)
at android.graphics.drawable.DrawableWrapper.draw(DrawableWrapper.java:240)
at android.view.View.drawBackground(View.java:21671)
at android.view.View.draw_Original(View.java:21435)
at android.view.View_Delegate.draw(View_Delegate.java:56)
at android.view.View.draw(View.java:21417)
at android.view.View.draw_Original(View.java:21317)
at android.view.View_Delegate.draw(View_Delegate.java:68)
at android.view.View.draw(View.java:21089)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4388)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:4388)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4149)
at android.view.View.draw_Original(View.java:21446)
at android.view.View_Delegate.draw(View_Delegate.java:56)
at android.view.View.draw(View.java:21417)
at android.view.View.draw_Original(View.java:21317)
at android.view.View_Delegate.draw(View_Delegate.java:68)
at android.view.View.draw(View.java:21089)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4388)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:4388)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4149)
at android.view.View.draw_Original(View.java:21315)
at android.view.View_Delegate.draw(View_Delegate.java:68)
at android.view.View.draw(View.java:21089)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4388)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:4388)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4149)
at android.view.View.draw_Original(View.java:21315)
at android.view.View_Delegate.draw(View_Delegate.java:68)
at android.view.View.draw(View.java:21089)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4388)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:4388)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4149)
at android.view.View.draw_Original(View.java:21446)
at android.view.View_Delegate.draw(View_Delegate.java:56)
at android.view.View.draw(View.java:21417)
at android.view.View.draw_Original(View.java:21317)
at android.view.View_Delegate.draw(View_Delegate.java:68)
at android.view.View.draw(View.java:21089)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4388)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:4388)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4149)
at android.view.View.draw_Original(View.java:21446)
at android.view.View_Delegate.draw(View_Delegate.java:56)
at android.view.View.draw(View.java:21417)
at android.view.View.draw_Original(View.java:21317)
at android.view.View_Delegate.draw(View_Delegate.java:68)
at android.view.View.draw(View.java:21089)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4388)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:4388)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4149)
at android.view.View.draw_Original(View.java:21446)
at android.view.View_Delegate.draw(View_Delegate.java:56)
at android.view.View.draw(View.java:21417)
at android.widget.ScrollView.draw(ScrollView.java:1835)
at android.view.View.draw_Original(View.java:21317)
at android.view.View_Delegate.draw(View_Delegate.java:68)
at android.view.View.draw(View.java:21089)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4388)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:4388)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4149)
at android.view.View.draw_Original(View.java:21315)
at android.view.View_Delegate.draw(View_Delegate.java:68)
at android.view.View.draw(View.java:21089)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4388)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:4388)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4149)
at android.view.View.draw_Original(View.java:21446)
at android.view.View_Delegate.draw(View_Delegate.java:56)
at android.view.View.draw(View.java:21417)
at android.view.View.draw_Original(View.java:21317)
at android.view.View_Delegate.draw(View_Delegate.java:68)
at android.view.View.draw(View.java:21089)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4388)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:4388)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4149)
at android.view.View.draw_Original(View.java:21315)
at android.view.View_Delegate.draw(View_Delegate.java:68)
at android.view.View.draw(View.java:21089)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4388)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:4388)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4149)
at android.view.View.draw_Original(View.java:21315)
at android.view.View_Delegate.draw(View_Delegate.java:68)
at android.view.View.draw(View.java:21089)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4388)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:4388)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4149)
at android.view.View.draw_Original(View.java:21446)
at android.view.View_Delegate.draw(View_Delegate.java:56)
at android.view.View.draw(View.java:21417)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:404)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:565)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:425)
at com.android.layoutlib.bridge.BridgeRenderSession.render(BridgeRenderSession.java:115)
at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:142)
at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:124)
at com.android.tools.idea.rendering.RenderTask.lambda$null$11(RenderTask.java:894)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

this is the screenshot of my XML the edit text is there but not visible correctly here.

now, this is the Screenshot of the error below.

What I have tried

  1. Clean the project
  2. Rebuild the project
  3. Close Andorid Studio and open project again.
  4. Enable new layout rendering engine from Settings -> Experimental.
  5. Disable new layout rendering engine from Settings -> Experimental.
  6. Clean Invalid Cashes through File ---> Invalid Cahes/ Restart
  7. android:inputType="textNoSuggestions"
  8. android:inputType="number"
  9. android:inputType="text"
  10. infact i have tried all the input types one by one.
  11. android:enabled="true"
  12. android:focusableInTouchMode="true"
  13. android:focusable="true"
  14. Tried different Emulators.
  15. Tried it on physical Devices.
  16. i have tried to set it enabled through JAVA
  17. postcode.setEnabled(true);
  18. postcode.setFocusable(true);

can anyone please help me what can be the issue here ? Thank you!


回答1:


I was facing the same problem, I have got a solution. Hope it will be work for you.

Add android:background property inside EditText:

enter image description here




回答2:


add background property to your edit text.

 android:background="@color/colorAccent"


来源:https://stackoverflow.com/questions/63552928/android-4-0-1-xml-rendering-error-in-edittext-index0-size-0-vew-draw-fai

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!