【问题标题】:RecyclerView error No adapter attached;RecyclerView 错误未连接适配器;
【发布时间】:2017-11-18 22:41:42
【问题描述】:

我收到错误 E/RecyclerView:未连接适配器;跳过布局,我不知道我做错了什么。

我有一个家庭活动,它调用使用回收视图的第二个活动,但在执行时未显示 recyclerView,并且我在 logcat 中收到错误 noadaptated attach。 这是创建 recyclerView 的活动

public class SearchActivity extends AppCompatActivity implements SearchView.OnQueryTextListener {

Toolbar toolbar;
RecyclerView recyclerView;
PublisherRecyclerAdapter adapter;
RecyclerView.LayoutManager layoutManager;
ArrayList<Publisher> arrayList = new ArrayList<>();
ArrayList<Category> categories = new ArrayList<>();


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    toolbar = (Toolbar) findViewById(R.id.search_publisher_toolbar);
    setSupportActionBar(toolbar);
    recyclerView = (RecyclerView)findViewById(R.id.recyclerview);
    layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setHasFixedSize(true);
            llenarLista();
    adapter = new PublisherRecyclerAdapter(arrayList);
    recyclerView.setAdapter(adapter);
    getClassLoader().setDefaultAssertionStatus(true);
}


@Override
public boolean onCreateOptionsMenu(Menu menu){
    getMenuInflater().inflate(R.menu.menu_items,menu);
    MenuItem menuItem = menu.findItem(R.id.action_search);
    SearchView searchView =(SearchView) MenuItemCompat.getActionView(menuItem);
    searchView.setOnQueryTextListener(this);
    return true;

}

public void llenarLista(){

    arrayList.add(new Publisher("ES",
            "https://feeds.feedburner.com/andro4all",
            "http://cdn.marketplaceimages.windowsphone.com/v8/images/42ca5c19-9425-40fb-92ba-45136bc8bdb8?imageType=ws_icon_large",
            null));
    arrayList.add(new Publisher("EN",
            "https://www.theverge.com/rss/index.xml",
            "https://cdn.vox-cdn.com/images/verge/2.0/verge-icon-196x196.v503bbf1f91b9b655a6b9bb5bd0c3c9efff02826a.png",
            null));
    arrayList.add(new Publisher("ES",
            "https://feeds.feedburner.com/xataka2",
            "https://pbs.twimg.com/profile_images/801704006527623168/Lv_XrMvF.jpg",
            null));
    arrayList.add(new Publisher("ES",
            "https://feeds.feedburner.com/vidaextra",
            "https://pbs.twimg.com/profile_images/845190979648798721/sfRTD5B1_400x400.jpg",
            null));
    arrayList.add(new Publisher("ES",
            "https://feeds.feedburner.com/espinof",
            "https://pbs.twimg.com/profile_images/877185802509459456/GvMMxoHn.jpg",
            null));
    arrayList.add(new Publisher("ES",
            "https://feeds.feedburner.com/elblogsalmon2",
            "https://pbs.twimg.com/profile_images/849950964366880773/Ixps5i7I_400x400.jpg",
            null));
    arrayList.add(new Publisher("ES",
            "https://feeds.feedburner.com/genbeta",
            "https://i.pinimg.com/originals/a4/0d/f2/a40df2b2c56834df0620f50a3910286f.jpg",
            null));
    arrayList.add(new Publisher("ES",
            "http://agilismoatwork.blogspot.com/feeds/posts/default",
            "https://www.mti.cl/wp-content/uploads/2017/08/Patricio-Letelier.jpg",
            null));
}





@Override
public boolean onQueryTextSubmit(String query) {
    return false;
}

@Override
public boolean onQueryTextChange(String newText) {
    newText = newText.toLowerCase();
    ArrayList<Publisher> listaFiltrada = new ArrayList<>();
    for(Publisher publisher : arrayList){

        String url = publisher.getUrl().toLowerCase();
        if(url.contains(newText))
            listaFiltrada.add(publisher);
    }
    adapter.setFilter(listaFiltrada);

    return true;
}

}

这是适配器

public class PublisherRecyclerAdapter extends RecyclerView.Adapter<PublisherRecyclerAdapter.MyViewHolder> {
ArrayList<Publisher> arrayList = new ArrayList<>();

public PublisherRecyclerAdapter(ArrayList<Publisher> arrayList)

{

    this.arrayList = arrayList;

}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_layout_publisher,parent,false);

    return new MyViewHolder(view);
}

@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
    holder.p_url.setText(arrayList.get(position).getUrl());
    holder.p_lan.setText(arrayList.get(position).getLanguage());
    //Picasso.with(context).load(arrayList.get(position).getIcon()).into(holder.p_icon);







}

@Override
public int getItemCount() {
    return arrayList.size();
}


public static  class MyViewHolder extends RecyclerView.ViewHolder {

   // ImageView p_icon;
    TextView p_url;
    TextView p_lan;



    public MyViewHolder(View itemView) {
        super(itemView);
        //si sale algo mal mirar nombre del id
        //p_icon =(ImageView)itemView.findViewById(R.id.icono);
        p_url =(TextView)itemView.findViewById(R.id.url);
        p_lan = (TextView)itemView.findViewById(R.id.language);

    }



}

public void setFilter(ArrayList<Publisher> newList){
    arrayList = new ArrayList<>();
    arrayList.addAll(newList);
    notifyDataSetChanged();
}
}

我用主要活动、适配器和 xml 做了一个简单的项目,但我不知道如何解决这个错误。

你能帮帮我吗?

这里编辑是堆栈跟踪

11-19 11:38:24.922 3379-3379/? I/art: Not late-enabling -Xcheck:jni (already 
on)
11-19 11:38:24.969 3379-3379/com.pin.sergio.saturn W/art: Failed 
execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --
debuggable --instruction-set=x86_64 --instruction-set-
features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-
image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -
Xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default 
--dex-file=/data/app/com.pin.sergio.saturn-1/split_lib_dependencies_apk.apk 
--oat-file=/data/dalvik-cache/x86_64/data@app@com.pin.sergio.saturn-
1@split_lib_dependencies_apk.apk@classes.dex) because non-0 exit status
11-19 11:38:25.081 3379-3379/com.pin.sergio.saturn W/art: Failed 
execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --
debuggable --instruction-set=x86_64 --instruction-set-
features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-
image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -
Xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default 
--dex-file=/data/app/com.pin.sergio.saturn-1/split_lib_slice_0_apk.apk --
oat-file=/data/dalvik-cache/x86_64/data@app@com.pin.sergio.saturn-
1@split_lib_slice_0_apk.apk@classes.dex) because non-0 exit status
11-19 11:38:25.098 3379-3379/com.pin.sergio.saturn W/art: Failed 
execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --
debuggable --instruction-set=x86_64 --instruction-set-
features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-
image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -
Xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default 
--dex-file=/data/app/com.pin.sergio.saturn-1/split_lib_slice_1_apk.apk --
oat-file=/data/dalvik-cache/x86_64/data@app@com.pin.sergio.saturn-
1@split_lib_slice_1_apk.apk@classes.dex) because non-0 exit status
11-19 11:38:25.113 3379-3379/com.pin.sergio.saturn W/art: Failed 
execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --
debuggable --instruction-set=x86_64 --instruction-set-
features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-
image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -
Xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default 
--dex-file=/data/app/com.pin.sergio.saturn-1/split_lib_slice_2_apk.apk --
oat-file=/data/dalvik-cache/x86_64/data@app@com.pin.sergio.saturn-
1@split_lib_slice_2_apk.apk@classes.dex) because non-0 exit status
11-19 11:38:25.129 3379-3379/com.pin.sergio.saturn W/art: Failed 
execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --
debuggable --instruction-set=x86_64 --instruction-set-
features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-
image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -
Xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default 
--dex-file=/data/app/com.pin.sergio.saturn-1/split_lib_slice_3_apk.apk --
oat-file=/data/dalvik-cache/x86_64/data@app@com.pin.sergio.saturn-
1@split_lib_slice_3_apk.apk@classes.dex) because non-0 exit status
11-19 11:38:25.147 3379-3379/com.pin.sergio.saturn W/art: Failed 
execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --
debuggable --instruction-set=x86_64 --instruction-set-
features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-
image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -
Xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default 
--dex-file=/data/app/com.pin.sergio.saturn-1/split_lib_slice_4_apk.apk --
oat-file=/data/dalvik-cache/x86_64/data@app@com.pin.sergio.saturn-
1@split_lib_slice_4_apk.apk@classes.dex) because non-0 exit status
11-19 11:38:25.159 3379-3379/com.pin.sergio.saturn W/art: Failed 
execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --
debuggable --instruction-set=x86_64 --instruction-set-
features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-
image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -
Xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default 
--dex-file=/data/app/com.pin.sergio.saturn-1/split_lib_slice_5_apk.apk --
oat-file=/data/dalvik-cache/x86_64/data@app@com.pin.sergio.saturn-
1@split_lib_slice_5_apk.apk@classes.dex) because non-0 exit status
11-19 11:38:25.174 3379-3379/com.pin.sergio.saturn W/art: Failed 
execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --
debuggable --instruction-set=x86_64 --instruction-set-
features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-
image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -
Xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default 
--dex-file=/data/app/com.pin.sergio.saturn-1/split_lib_slice_6_apk.apk --
oat-file=/data/dalvik-cache/x86_64/data@app@com.pin.sergio.saturn-
1@split_lib_slice_6_apk.apk@classes.dex) because non-0 exit status
11-19 11:38:25.191 3379-3379/com.pin.sergio.saturn W/art: Failed 
execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --
debuggable --instruction-set=x86_64 --instruction-set-
features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-
image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -
Xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default 
--dex-file=/data/app/com.pin.sergio.saturn-1/split_lib_slice_7_apk.apk --
oat-file=/data/dalvik-cache/x86_64/data@app@com.pin.sergio.saturn-
1@split_lib_slice_7_apk.apk@classes.dex) because non-0 exit status
11-19 11:38:25.210 3379-3379/com.pin.sergio.saturn W/art: Failed 
execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --
debuggable --instruction-set=x86_64 --instruction-set-
features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-
image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -
Xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default 
--dex-file=/data/app/com.pin.sergio.saturn-1/split_lib_slice_8_apk.apk --
oat-file=/data/dalvik-cache/x86_64/data@app@com.pin.sergio.saturn-
1@split_lib_slice_8_apk.apk@classes.dex) because non-0 exit status
11-19 11:38:25.225 3379-3379/com.pin.sergio.saturn W/art: Failed 
execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --
debuggable --instruction-set=x86_64 --instruction-set-
features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-
image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -
Xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default 
--dex-file=/data/app/com.pin.sergio.saturn-1/split_lib_slice_9_apk.apk --
oat-file=/data/dalvik-cache/x86_64/data@app@com.pin.sergio.saturn-
1@split_lib_slice_9_apk.apk@classes.dex) because non-0 exit status
11-19 11:38:25.226 3379-3379/com.pin.sergio.saturn W/System: ClassLoader 
referenced unknown path: /data/app/com.pin.sergio.saturn-1/lib/x86_64
11-19 11:38:25.228 3379-3379/com.pin.sergio.saturn I/InstantRun: starting 
instant run server: is main process
11-19 11:38:25.301 3379-3379/com.pin.sergio.saturn W/art: Before Android 
4.1, method android.graphics.PorterDuffColorFilter

android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) 会错误地覆盖 android.graphics 中的包私有方法.drawable.Drawable 11-19 11:38:25.609 3379-3417/com.pin.sergio.saturn D/OpenGLRenderer: 使用 EGL_SWAP_BEHAVIOR_PRESERVED: true

                                                                 [ 11-19 11:38:25.611  3379: 3379 D/         ]
                                                                 HostConnection::get() New Host Connection established 0x7f665a55d6c0, tid 3379


                                                                 [ 11-19 11:38:25.612  3379: 3379 W/         ]
                                                                 Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 

                                                                 [ 11-19 11:38:25.693  3379: 3417 D/         ]
                                                                 HostConnection::get() New Host Connection established 0x7f6665cd1360, tid 3417


                                                                 [ 11-19 11:38:25.694  3379: 3417 W/         ]
                                                                 Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 
11-19 11:38:25.695 3379-3417/com.pin.sergio.saturn I/OpenGLRenderer: 
Initialized EGL, version 1.4
11-19 11:38:25.695 3379-3417/com.pin.sergio.saturn W/OpenGLRenderer: Failed 
to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
11-19 11:38:25.706 3379-3417/com.pin.sergio.saturn D/EGL_emulation: 
eglCreateContext: 0x7f6665cf22a0: maj 2 min 0 rcv 2
11-19 11:38:25.714 3379-3417/com.pin.sergio.saturn D/EGL_emulation: 
eglMakeCurrent: 0x7f6665cf22a0: ver 2 0 (tinfo 0x7f665a4315c0)
11-19 11:38:25.742 3379-3417/com.pin.sergio.saturn D/EGL_emulation: 
eglMakeCurrent: 0x7f6665cf22a0: ver 2 0 (tinfo 0x7f665a4315c0)
11-19 11:38:25.767 3379-3379/com.pin.sergio.saturn E/RecyclerView: No 
adapter attached; skipping layout
11-19 11:38:25.795 3379-3379/com.pin.sergio.saturn W/art: Before Android 
4.1, method int 
android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, 
boolean) would have incorrectly overridden the package-private method in 
android.widget.ListView
11-19 11:38:25.842 3379-3379/com.pin.sergio.saturn E/RecyclerView: No 
adapter attached; skipping layout
11-19 11:38:26.432 3379-3379/com.pin.sergio.saturn W/Glide: Failed to find 
GeneratedAppGlideModule. You should include an annotationProcessor compile 
dependency on com.github.bumptech.glide:compiler in your application and a 
@GlideModule annotated AppGlideModule implementation or LibraryGlideModules 
will be silently ignored
11-19 11:38:31.057 3379-3417/com.pin.sergio.saturn D/EGL_emulation: 
eglMakeCurrent: 0x7f6665cf22a0: ver 2 0 (tinfo 0x7f665a4315c0)
11-19 11:38:31.058 3379-3417/com.pin.sergio.saturn D/EGL_emulation: 
eglMakeCurrent: 0x7f6665cf22a0: ver 2 0 (tinfo 0x7f665a4315c0)
11-19 11:38:31.108 3379-3417/com.pin.sergio.saturn D/EGL_emulation: 
eglMakeCurrent: 0x7f6665cf22a0: ver 2 0 (tinfo 0x7f665a4315c0)
11-19 11:38:31.131 3379-3417/com.pin.sergio.saturn D/EGL_emulation: 
eglMakeCurrent: 0x7f6665cf22a0: ver 2 0 (tinfo 0x7f665a4315c0)
11-19 11:38:31.166 3379-3417/com.pin.sergio.saturn D/EGL_emulation: 
eglMakeCurrent: 0x7f6665cf22a0: ver 2 0 (tinfo 0x7f665a4315c0)
11-19 11:38:31.221 3379-3417/com.pin.sergio.saturn E/Surface: 
getSlotFromBufferLocked: unknown buffer: 0x7f6665cf2980
11-19 11:38:31.228 3379-3417/com.pin.sergio.saturn D/OpenGLRenderer: 
endAllStagingAnimators on 0x7f665884ec00 (StateListDrawable) with handle 
0x7f6658bc7040
11-19 11:38:35.770 3379-3417/com.pin.sergio.saturn D/EGL_emulation: 
eglMakeCurrent: 0x7f6665cf22a0: ver 2 0 (tinfo 0x7f665a4315c0)
11-19 11:38:35.843 3379-3417/com.pin.sergio.saturn E/Surface: 
getSlotFromBufferLocked: unknown buffer: 0x7f66590a7d60
11-19 11:39:53.563 3379-3417/com.pin.sergio.saturn D/EGL_emulation: 
eglMakeCurrent: 0x7f6665cf22a0: ver 2 0 (tinfo 0x7f665a4315c0)
11-19 11:39:53.612 3379-3417/com.pin.sergio.saturn D/EGL_emulation: 
eglMakeCurrent: 0x7f6665cf22a0: ver 2 0 (tinfo 0x7f665a4315c0)
11-19 11:39:53.638 3379-3417/com.pin.sergio.saturn D/EGL_emulation: 
eglMakeCurrent: 0x7f6665cf22a0: ver 2 0 (tinfo 0x7f665a4315c0)
11-19 11:39:53.640 3379-3417/com.pin.sergio.saturn E/Surface: 
getSlotFromBufferLocked: unknown buffer: 0x7f6665cf28e0
11-19 11:40:59.126 3379-3417/com.pin.sergio.saturn D/EGL_emulation: 
eglMakeCurrent: 0x7f6665cf22a0: ver 2 0 (tinfo 0x7f665a4315c0)
11-19 11:40:59.206 3379-3417/com.pin.sergio.saturn E/Surface: 
getSlotFromBufferLocked: unknown buffer: 0x7f6665cf3f60
11-19 11:41:04.792 3379-3417/com.pin.sergio.saturn D/EGL_emulation: 
eglMakeCurrent: 0x7f6665cf22a0: ver 2 0 (tinfo 0x7f665a4315c0)
11-19 11:41:04.795 3379-3417/com.pin.sergio.saturn E/Surface: 
getSlotFromBufferLocked: unknown buffer: 0x7f6665cf2480

我再次获取堆栈跟踪,并且出现了我问的错误并且得到了这个:

11-19 16:21:59.562 3050-3050/com.pin.sergio.saturn E/RecyclerView: No 
adapter attached; skipping layout
11-19 16:21:59.605 3050-3050/com.pin.sergio.saturn W/art: Before Android 
4.1, method int 
android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, 
boolean) would have incorrectly overridden the package-private method in 
android.widget.ListView
11-19 16:21:59.731 3050-3050/com.pin.sergio.saturn E/RecyclerView: No 
adapter attached; skipping layout
11-19 16:22:00.217 3050-3050/com.pin.sergio.saturn W/Glide: Failed to find 
GeneratedAppGlideModule. You should include an annotationProcessor compile 
dependency on com.github.bumptech.glide:compiler in your application and a 
@GlideModule annotated AppGlideModule implementation or LibraryGlideModules 
will be silently ignored

【问题讨论】:

  • 你能显示完整的堆栈跟踪吗?
  • 我添加了stackTrace,感谢您回答我的问题
  • 我能够通过删除两个类然后再次写入来解决此错误。只是两个java文件,然后删除原来的。
  • 我也这样做了,但还是不行
  • 堆栈跟踪看起来不对 - 也不是您在标题中发布的错误

标签: android android-recyclerview


【解决方案1】:

使用这个

   LinearLayoutManager mLinearLayoutManager=new LinearLayoutManager(this);
   receylerview.setLayoutManager(mLinearLayoutManager);

【讨论】:

  • 错误依旧,recyclerView没有显示
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-02-04
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
  • 2021-01-11
  • 1970-01-01
  • 2021-12-07
相关资源
最近更新 更多