gpt4 book ai didi

java - RecyclerView 没有 LayoutManager android.support.v7.widget.RecyclerView

转载 作者:行者123 更新时间:2023-11-29 18:28:11 26 4
gpt4 key购买 nike

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.liliyu.easyresumebuilder, PID: 11145
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.liliyu.easyresumebuilder/com.example.liliyu.easyresumebuilder.MainActivity}: android.view.InflateException: Binary XML file line #10: RecyclerView has no LayoutManager android.support.v7.widget.RecyclerView{df7f7c9 VFED..... ......I. 0,0-0,0 #7f070061 app:id/main_activity1}, adapter:null, layout:null, context:com.example.liliyu.easyresumebuilder.MainActivity@2857d33
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2434)

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_activity1"
tools:context="com.example.liliyu.easyresumebuilder.MainActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/spacing_medium"
android:orientation="vertical">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:id="@+id/user_name_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_small"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/user_picture"
android:gravity="center_vertical">

<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/caption_text_size"
tools:text="Your name" />

</LinearLayout>

<TextView
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/user_name_layout"
android:layout_toLeftOf="@+id/user_picture"
tools:text="Your email" />

</RelativeLayout>

</LinearLayout>

</android.support.v7.widget.RecyclerView>

主 Activity .java

@SuppressWarnings("ConstantConditions")
public class MainActivity extends AppCompatActivity {

private BasicInfo basicInfo;
private RecyclerView recyclerView = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loadData();
setupUI();
}

private void setupUI() {
setContentView(R.layout.activity_main);
recyclerView = (RecyclerView) findViewById(R.id.main_activity1);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
setupBasicInfo();

}

private void setupBasicInfo() {
((TextView) findViewById(R.id.name)).setText(TextUtils.isEmpty(basicInfo.name)
? "Your name"
: basicInfo.name);
((TextView) findViewById(R.id.email)).setText(TextUtils.isEmpty(basicInfo.email)
? "Your email"
: basicInfo.email);

ImageView userPicture = (ImageView) findViewById(R.id.user_picture);
if (basicInfo.imageUri != null) {
ImageUtils.loadImage(this, basicInfo.imageUri, userPicture);
} else {
userPicture.setImageResource(R.drawable.user_ghost);
}

findViewById(R.id.edit_basic_info).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, BasicInfoEditActivity.class);
intent.putExtra(BasicInfoEditActivity.KEY_BASIC_INFO, basicInfo);
startActivityForResult(intent, REQ_CODE_EDIT_BASIC_INFO);
}
});
}

private void loadData() {
connectAndGetApiData();
basicInfo = basicInfo == null ? new BasicInfo() : basicInfo;
}


public void connectAndGetApiData() {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
ResumeService resumeService=retrofit.create(ResumeService.class);
Call<Resume> call =resumeService.getResume();
try {
call.enqueue(new Callback<Resume>() {
@Override
public void onResponse(Call<Resume> call, Response<Resume> response) {
recyclerView.setAdapter(new ResumeAdapter(getApplicationContext(),response.body()));

}

@Override
public void onFailure(Call<Resume> call, Throwable throwable) {
System.out.println(throwable.toString());
}
});
}catch(Throwable e){
e.printStackTrace();
}

}
}

最佳答案

将 parentLayout(可以是 LinearLayout)添加到您的 RecyclerView 并从您的 RecyclerView 中删除子布局。

关于java - RecyclerView 没有 LayoutManager android.support.v7.widget.RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57760383/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com