[英]Android: Expected resource of type id
我在Android Studio中遇到一个奇怪的问题。
我的activity_chords_list.xml文件中包含一个RecyclerView
,如下所示:
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chords_recycler"
android:layout_below="@+id/layout_top"
android:layout_alignParentStart="true"
android:layout_marginTop="50dp" />
但是在我的onCreate()
方法中无法识别:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chords_list);
chordsList = (RecyclerView) findViewById(R.layout.chords_recycler);
并且出现以下两个错误:
Expected resource of type ID
cannot resolve symbol chords_recycler
关于如何解决它的任何想法?
更改
android:id="@id/chords_recycler"
对于
android:id="@+id/chords_recycler"
从文档中 :
加号(+)表示这是一个新的资源名称,必须创建该资源并将其添加到我们的资源中(在R.java文件中)。
您需要使用R.id.chords_recycler
进行访问:
chordsList = (RecyclerView) findViewById(R.id.chords_recycler);
我认为您应该使用此:
chordsList = (RecyclerView) findViewById(R.id.chords_recycler);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.