我正在尝试在现有项目中使用RecyclerView,构建时没有错误,但充气时没有发现RecyclerView类错误。看不到我在做什么错。感谢您的帮助!
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
public class search_item1 extends RecyclerView.Adapter<search_item1.ViewHolder> {
private ArrayList<String> mData = null ;
// 아이템 뷰를 저장하는 뷰홀더 클래스.
public class ViewHolder extends RecyclerView.ViewHolder {
TextView textView1 ;
ViewHolder(View itemView) {
super(itemView) ;
// 뷰 객체에 대한 참조. (hold strong reference)
textView1 = itemView.findViewById(R.id.text2) ;
}
}
// 생성자에서 데이터 리스트 객체를 전달받음.
search_item1(ArrayList<String> list) {
mData = list ;
}
// onCreateViewHolder() - 아이템 뷰를 위한 뷰홀더 객체 생성하여 리턴.
@Override
public search_item1.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = parent.getContext() ;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) ;
View view = inflater.inflate(R.layout.search2_item, parent, false) ;
search_item1.ViewHolder vh = new search_item1.ViewHolder(view) ;
return vh ;
}
// onBindViewHolder() - position에 해당하는 데이터를 뷰홀더의 아이템뷰에 표시.
@Override
public void onBindViewHolder(search_item1.ViewHolder holder, int position) {
String text = mData.get(position) ;
holder.textView1.setText(text) ;
}
// getItemCount() - 전체 데이터 갯수 리턴.
@Override
public int getItemCount() {
return mData.size() ;
}
}
请提供此代码的帮助 直到我死的那一天,我仰望天空。 我希望你不要羞愧 即使在风中 我很伤心。 满怀星光的心 爱所有垂死的。 而且我得到的方式 我必须走路。
今晚的星星再次在风中摩擦。
我有这样的错误:
2019-11-15 00:38:21.857 7571-7571/sungjusin.gatag3 E/AndroidRuntime: FATAL EXCEPTION: main
Process: sungjusin.gatag3, PID: 7571
android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.RecyclerView" on path: DexPathList[[zip file "/data/app/sungjusin.gatag3-3-2f5OVMsm7-VXSs_MYnRg==/base.apk"],nativeLibraryDirectories=[/data/app/sungjusin.gatag3-3-2f5OVMsm7-VXSs_MYnRg==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at sungjusin.gatag3.search_item1.onCreateViewHolder(search_item1.java:67)
at sungjusin.gatag3.search_item1.onCreateViewHolder(search_item1.java:13
)
答案 0 :(得分:0)
用android.support.v7.widget.RecyclerView
替换xml文件中的androidx.recyclerview.widget.RecyclerView
答案 1 :(得分:0)
您习惯使用androidx
,因此不能使用android.support.v7,
所以尝试使用:
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recyclerView"/>
代替
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recyclerView"/>