No adapter attached; skipping layout error You're working so hard. Help me crying

Asked 2 years ago, Updated 2 years ago, 28 views

public class frag extends ActionBarActivity{
    private LinearLayoutManager lLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frag);
        setTitle(null);

        Toolbar topToolBar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(topToolBar);
        topToolBar.setLogo(R.drawable.logo);
        topToolBar.setLogoDescription(getResources().getString(R.string.logo_desc));

        List<Itemobject> rowListItem = getAllItemList();
        lLayout = new LinearLayoutManager(frag.this);

        RecyclerView rView = (RecyclerView) findViewById(R.id.recycler_view);
        rView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        RecyclerViewAdapter rcAdapter = new RecyclerViewAdapter(frag.this, rowListItem);
        rView.setAdapter(rcAdapter);
    }
    public static class Main extends Fragment{
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            return inflater.inflate(R.layout.activity_frag, null);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        int id = item.getItemId();


        if (id == R.id.action_settings) {
            return true;
        }
        if (id == R.id.action_refresh) {
            Toast.makeText(frag.this, "Refresh App", Toast.LENGTH_LONG).show();
        }
        if (id == R.id.action_new) {
            Toast.makeText(frag.this, "Create Text", Toast.LENGTH_LONG).show();
        }

        return super.onOptionsItemSelected(item);
    }

    private List<Itemobject> getAllItemList() {

        List<Itemobject> allItems = new ArrayList<Itemobject>();
        allItems.add(new Itemobject("United States", R.drawable.newyork));
        allItems.add(new Itemobject("Canada", R.drawable.canada));
        allItems.add(new Itemobject("United Kingdom", R.drawable.uk));
        allItems.add(new Itemobject("Germany", R.drawable.germany));
        allItems.add(new Itemobject("Sweden", R.drawable.sweden));

        return allItems;
    }
  }
}

android

2022-09-22 21:11

2 Answers

The No adapter attached; skipping layout error log occurs when the adapter is not set at the time the recirculation view is initialized. I don't think there's anything wrong with the code you posted, but it's strange.

I think we need to check if the log caused by the code is correct. In addition, this phenomenon only prints the error log, not shutting down the app. The error log may be annoying, but I want to tell you that you don't have to worry too much if you can't find the problem.


2022-09-22 21:11

I want to do that too, but if I watch it separately, there is a recycling view, but when I watch it with the fragment, it doesn't come up, so I can't ignore it ㅠ<


2022-09-22 21:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.