Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

B-runo

Crash Aplicativo AndroidStudio: E/RecyclerView: No adapter attached;

Recommended Posts

Por favor preciso de ajuda pois já quebrei a cabeça tentando arrumar isso e nao consegui.

 

Estou estudando android em um livro e estou seguindo passo a passo o codigo que ele pede, estava funcionando tudo bem ate chegar nessa parte em que ele diz pra fazer um recyclerView para adicionar uma lista de carros, já fiz tudo mas quando mando testar o aplicativo no emuladoro aplicativo crasha e no emulador aparece o erro :

 

01-15 13:11:25.703 5561-5561/com.hexata.carros E/RecyclerView: No adapter attached; skipping layout

 

 

 

e mais abaixo:

 

 

 

01-15 13:11:25.704 5561-5561/com.hexata.carros E/RecyclerView: No adapter attached; skipping layout
01-15 13:11:25.745 5561-5561/com.hexata.carros D/AndroidRuntime: Shutting down VM
01-15 13:11:25.748 5561-5561/com.hexata.carros E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hexata.carros, PID: 5561
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.support.v7.widget.RecyclerView$LayoutManager.canScrollVertically()' on a null object reference
at android.support.v7.widget.RecyclerView.computeVerticalScrollRange(RecyclerView.java:1654)
at android.view.View.onDrawScrollBars(View.java:13924)
at android.view.View.onDrawForeground(View.java:17657)
at android.view.View.draw(View.java:16189)
at android.support.v7.widget.RecyclerView.draw(RecyclerView.java:3097)
at android.view.View.updateDisplayListIfDirty(View.java:15174)
at android.view.View.draw(View.java:15948)
at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
at android.view.View.updateDisplayListIfDirty(View.java:15169)
at android.view.View.draw(View.java:15948)
at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
at android.view.View.draw(View.java:16181)
at android.support.v4.view.ViewPager.draw(ViewPager.java:2262)
at android.view.View.updateDisplayListIfDirty(View.java:15174)
at android.view.View.draw(View.java:15948)
at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
at android.view.View.updateDisplayListIfDirty(View.java:15169)
at android.view.View.draw(View.java:15948)
at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
at android.view.View.updateDisplayListIfDirty(View.java:15169)
at android.view.View.draw(View.java:15948)
at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
at android.view.View.updateDisplayListIfDirty(View.java:15169)
at android.view.View.draw(View.java:15948)
at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1229)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
at android.view.View.draw(View.java:16181)
at android.view.View.updateDisplayListIfDirty(View.java:15174)
at android.view.View.draw(View.java:15948)
at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
at android.support.design.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1077)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
at android.view.View.draw(View.java:16181)
at android.view.View.updateDisplayListIfDirty(View.java:15174)
at android.view.View.draw(View.java:15948)
at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
at android.view.View.updateDisplayListIfDirty(View.java:15169)
at android.view.View.draw(View.java:15948)
at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
at android.view.View.updateDisplayListIfDirty(View.java:15169)
at android.view.View.draw(View.java:15948)
at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
at android.view.View.updateDisplayListIfDirty(View.java:15169)
at android.view.View.draw(View.java:15948)
at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
at android.view.View.updateDisplayListIfDirty(View.java:15169)
at android.view.View.draw(View.java:15948)
at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
at android.view.View.draw(View.java:16181)
at com.android.internal.policy.PhoneWindow$DecorView.draw(PhoneWindow.java:2690)
at android.view.View.updateDisplayListIfDirty(View.java:15174)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:281)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:287)
at android.view.ThreadedRenderer.draw(ThreadedRende
Meu codigo fonte está aqui:
package com.hexata.carros.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Toast;

import com.hexata.carros.R;
import com.hexata.carros.adapter.CarroAdapter;
import com.hexata.carros.domain.Carro;
import com.hexata.carros.domain.CarroService;

import java.util.List;

public class CarrosFragment extends BaseFragment{

protected RecyclerView recyclerView;
private List<Carro> carros;
private LinearLayoutManager mLayoutManager;

private String tipo;

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

if (getArguments() != null)
{
this.tipo = getArguments().getString("tipo");
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.fragment_carros, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
mLayoutManager = new LinearLayoutManager(getActivity());

recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setHasFixedSize(true);
return view;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
taskCarros();
}

private void taskCarros() {
//Busca carros
this.carros = CarroService.getCarros(getContext(), tipo);

//Atuliza a lista
recyclerView.setAdapter(new CarroAdapter(getContext(), carros, onClickCarro()));
}

private CarroAdapter.CarroOnClickListener onClickCarro() {
return new CarroAdapter.CarroOnClickListener()
{
@Override
public void onClickCarro(View view, int idx)
{
Carro c = carros.get(idx);
Toast.makeText(getContext(), "Carro: " + c.nome, Toast.LENGTH_SHORT).show();
}
};
}


}

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.