Ich benutze Retrofit zum Abrufen von JSON-Daten von REST API. Ich habe Retrofit implementiert, aber nach dem Start der App stürzt es mit einem Fehler ab: RecyclerView: No adapter attached; skipping layout
. Ich benutze eine vorherige Antwort, aber keine von ihnen löst mein Problem. Hier ist mein Code:RecyclerView: Kein Adapter angeschlossen; Layout überspringen während mit Retro-Fit zu holen JSON
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cinsio_notif);
initViews();
private void initViews() {
recyclerView = (RecyclerView) findViewById(R.id.noti_recyle);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(layoutManager);
loadJSON();
}
private void loadJSON() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://chikoop.com/api/index.php/")
.addConverterFactory(GsonConverterFactory.create())
.build();
notiIterface request = retrofit.create(notiIterface.class);
Call<JSONResponse> call = request.getNotification(userId, sessionId);
call.enqueue(new Callback<JSONResponse>() {
@Override
public void onResponse(Call<JSONResponse> call, Response<JSONResponse> response) {
JSONResponse jsonResponse = response.body();
data = new ArrayList<>(Arrays.asList(jsonResponse.getAndroid()));
adapter = new noti_adapter(data, getApplicationContext());
recyclerView.setAdapter(adapter);
}
@Override
public void onFailure(Call<JSONResponse> call, Throwable t) {
}
});
}
Und mein xml-Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/textColor">
<include
android:id="@+id/custome_actionbar"
layout="@layout/cusmote_actionbar"
android:layout_width="match_parent"
android:layout_height="60dp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/noti_recyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/custome_actionbar">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
-------------------------- ------->
Wenn jemand meinen Adapter Code benötigt:
List<noti_sec> noti_list;
private Context context;
//Constructor of this class
public noti_adapter(List<noti_sec> noti_list, Context context){
super();
//Getting all superheroes
this.noti_list = noti_list;
this.context = context;
}
public static class notiViewHolder extends RecyclerView.ViewHolder {
CircleImageView profile_pic;
TextView name;
TextView about_noti;
TextView noti_time;
ImageView from;
public notiViewHolder(View v) {
super(v);
profile_pic = (CircleImageView) v.findViewById(R.id.profile_image);
name = (TextView) v.findViewById(R.id.name);
about_noti = (TextView) v.findViewById(R.id.notif_about);
noti_time = (TextView) v.findViewById(R.id.noti_time);
from = (ImageView) v.findViewById(R.id.msg_img);
}
}
@Override
public noti_adapter.notiViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.noti_msg_screen, parent, false);
return new notiViewHolder(view);
}
@Override
public void onBindViewHolder(notiViewHolder holder, final int position) {
holder.profile_pic.setImageResource(R.drawable.border_frame1);
holder.name.setText(noti_list.get(position).getUsername());
holder.about_noti.setText(noti_list.get(position).getNoti_msg());
Picasso.with(context)
.load(image)
.into(holder.from);
}
@Override
public int getItemCount() {
return noti_list.size();
}
Fehlerprotokoll Katze:
02-15 20:12:16.247 13338-13338/com.release.chikoopapp E/RecyclerView: No adapter attached; skipping layout
02-15 20:12:16.248 13338-13338/com.release.chikoopapp E/RecyclerView: No adapter attached; skipping layout
02-15 20:12:16.406 13338-13338/com.release.chikoopapp D/AndroidRuntime: Shutting down VM
02-15 20:12:16.415 13338-13338/com.release.chikoopapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.release.chikoopapp, PID: 13338
java.lang.RuntimeException: Empty builders!
at com.nightonke.boommenu.ExceptionManager.judge(ExceptionManager.java:71)
at com.nightonke.boommenu.ExceptionManager.judge(ExceptionManager.java:27)
at com.nightonke.boommenu.BoomMenuButton.doLayoutJobs(BoomMenuButton.java:346)
at com.nightonke.boommenu.BoomMenuButton.access$600(BoomMenuButton.java:55)
at com.nightonke.boommenu.BoomMenuButton$8.run(BoomMenuButton.java:1013)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Sind Sie sicher, dass Ihr Adaptercode korrekt ist? –
@Giovanni Terlingen Wenn du diesen Code brauchst, werde ich ihn in edit answer posten. –
Können Sie auch den StackTrace bereitstellen, und nicht nur die Nachricht? –