Error in Android Studio 'The <fileName> stopped. ' caused by Index: 0, Size: 0

Asked

Viewed 26 times

0

Hi, guys. That’s my first question here at Stackoverflow. I am facing a problem in Android Studio: the application is installed on mobile but does not work, nor opens. The error is 'The nameApplicative has stopped.'

I believe the error is related to the error:

Index: 0, Size: 0
View draw failed (Details)
Tip: Try to refresh the layout.

I’ve tried to

The 'Use new Layout Rendering Engine' option. But when I click on this option, it asks to restart Android Studio. After restarting, nothing happens. It stays the way it was. I tried to find some plugin related to Layout Rederization to solve this problem. But I do not understand plugins.

Stack Trace:

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: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: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:143)
    at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:125)
    at com.android.tools.idea.rendering.RenderTask.lambda$null$11(RenderTask.java:966)
    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)

The code:

package com.example.minhasanotacoes;

import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;

import android.database.Cursor;
import android.view.View;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

import com.example.minhasanotacoes.bancodedados.BancoDeDados;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tela_inicial);

        BancoDeDados bancoDeDados = new BancoDeDados(getBaseContext());
        final Cursor cursor = bancoDeDados.obterAnotacoes();

        String[] nomeCampos = new String[] {"_id", "titulo"};
        int[] idViews = new int[] {R.id.labelId, R.id.labelTitulo};

        SimpleCursorAdapter adaptador = new SimpleCursorAdapter(getBaseContext(),
                R.layout.modelo_lista, cursor, nomeCampos,
                idViews, 0);

        ListView lista = (ListView)findViewById(R.id.listaDeNotas);
        lista.setAdapter(adaptador);
    }

    public void abrirTelaCriarNovaAnotacao(View v){
        Intent startNewActivity = new Intent(this, CriarAnotacao.class);
        startActivity(startNewActivity);
    }
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.