Mi problema es que me aparece en blanco mi recyclerView, al ver el log me aparece el error " E/RecyclerView: No adapter attached; skipping layout", he intetado solucionarlo viendo otros post sobre esto pero aun no lo pude solucionar. Sé que tengo que mover alguna linea que estoy declarando con anterioridad, pero no se cual. Si me ayudan a identificar cual, les agradecería.
acá va mi Main activity
RecyclerView recyclerViewRowset;
MyApiAdapter myApiAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerViewRowset = findViewById(R.id.recycler_view);
recyclerViewRowset.setAdapter(myApiAdapter);
/*user = findViewById(R.id.Usuario);
contraseña = findViewById(R.id.Password);
prueba = findViewById(R.id.prueba);
prueba4= findViewById(R.id.prueba4);*/
informeConexion = findViewById(R.id.conexionActivity);
prueba3 = findViewById(R.id.prueba3);
}
public void Prueba(View v){
recyclerViewRowset = findViewById(R.id.recycler_view);
recyclerViewRowset.setLayoutManager(new LinearLayoutManager(this));
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(" http://137.116.116.34:91/")
.addConverterFactory(GsonConverterFactory.create())
.build();
Conexion conexion = retrofit.create(Conexion.class);
Cuerpo login3 = new Cuerpo("xxx", "xxx", "xx");
Call<LoginUser> call2 = conexion.getUser(login3);
call2.enqueue(new Callback<LoginUser>() {
@SuppressLint("SetTextI18n")
@Override
public void onResponse(Call<LoginUser> call, Response<LoginUser> response) {
int statusCode = response.code();
if(statusCode == 200) {
informeConexion.setText("code: " + response.code() + " Conexión exitosa " + "\n");
Mq0302aDatareq contactList = response.body().getMq0302a();
Toast.makeText(MainActivity.this, "OUTPUT : "+response.body(), Toast.LENGTH_LONG).show();
Log.d("MainActivity", "posts loaded from API");
// Toast.makeText(MainActivity.this, "OUTPUT : "+response.body().getContacts(), Toast.LENGTH_LONG).show(); Log.d("MainActivity", "posts loaded from API"); List<Contact> contactList = response.body().getContacts(); for(int i = 0; i<contactList.size(); i++)
for(int i = 1; i<contactList.getRowset().size(); i++) {
String tableId = contactList.getTableId();
int moreRecords = contactList.getRecords();
boolean records = contactList.getMoreRecords();
ArrayList<Rowset> rowset = (ArrayList<Rowset>) contactList.getRowset();
String cliente = rowset.get(i).getCliente();
int home = rowset.get(i).getCantidad();
int office = rowset.get(i).getOrden();
prueba3.setText("Cliente: " + cliente + "\n" + "Cantidad: " + home + "\n" +"Orden: " + office + "\n");
Toast.makeText(MainActivity.this, "OUTPUT : "+statusCode +", "+ tableId +", "+ moreRecords +", "+ records +",¨ " + cliente +"," + home +","+ office , Toast.LENGTH_LONG).show();
myApiAdapter = new MyApiAdapter(rowset, this);
//MyApiAdapter myApiAdapter;
/* prueba.setText("Cliente: " + cliente + "\n" + "Cantidad: " + home + "\n" +"Orden: " + office + "\n");
prueba3.setText("Tabla: " + tableId + "\n" + "moreRecords: " + moreRecords + "\n" +"records: " + records );*/
}
}else {
// prueba3.setText("code: " + response.code() + " Conexión fallida " + "\n");
Toast.makeText(MainActivity.this, "ERROR " + statusCode, Toast.LENGTH_LONG).show();
}
}
MyApiAdapter myApiAdapter;
@Override
public void onFailure(Call<LoginUser> call, Throwable t) {
// prueba3.setText("problema: " +t.getMessage());
Toast.makeText(MainActivity.this, "ERROR " , Toast.LENGTH_LONG).show();
}
});
}
mi adaptador
private ArrayList<Rowset> recyclerDataArrayList;
public Context mcontext;
private static Conexion API_SERVICE;
public static Conexion getApiService() {
// Creamos un interceptor y le indicamos el log level a usar
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
// Asociamos el interceptor a las peticiones
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
String baseUrl = "http://137.116.116.34:91/";
if (API_SERVICE == null) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient.build()) // <-- usamos el log level
.build();
API_SERVICE = retrofit.create(Conexion.class);
}
return API_SERVICE;
}
public MyApiAdapter(ArrayList<Rowset> recyclerDataArrayList, Callback<LoginUser> mainActivity) {
this.recyclerDataArrayList = recyclerDataArrayList;
this.mcontext = mcontext;
}
@NonNull
@Override
public MyApiAdapter.ViewHolder onCreateViewHolder( ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.card_row, viewGroup,false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(MyApiAdapter.ViewHolder viewHolder, int i) {
//ArrayList<Rowset> modal = (ArrayList<Rowset>)recyclerDataArrayList;
viewHolder.tv_name.setText(recyclerDataArrayList.get(i).getNroCliente());
viewHolder.tv_version.setText(recyclerDataArrayList.get(i).getCliente());
viewHolder.tv_api_level.setText(recyclerDataArrayList.get(i).getOrden());
}
@Override
public int getItemCount() {
return recyclerDataArrayList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
private TextView tv_name,tv_version,tv_api_level;
public ViewHolder(View view) {
super(view);
tv_name = (TextView)view.findViewById(R.id.tv_name);
tv_version = (TextView)view.findViewById(R.id.tv_version);
tv_api_level = (TextView)view.findViewById(R.id.tv_api_level);
}
}
}
y agrego mi XML, quizas el error esta ahi
androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/white"
tools:context=".MainActivity">
<TextView
android:id="@+id/conexionActivity"
android:layout_width="162dp"
android:layout_height="37dp"
android:hint="Estado de la conexión"
android:textStyle="normal|bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.508"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.034" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="116dp"
android:clickable="true"
android:onClick="Prueba"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="381dp"
android:layout_height="495dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.493"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.277" />
<TextView
android:id="@+id/prueba3"
android:layout_width="316dp"
android:layout_height="428dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
y acá el LOG
.ConscryptPlatform$platformTrustManager$2> 2022-03-23 14:44:18.664 13773-13773/com.example.finalvm I/art: Rejecting re-init on previously-failed class java.lang.Class<okhttp3.internal.platform.ConscryptPlatform$platformTrustManager$2> 2022-03-23 14:44:18.721 13773-13773/com.example.finalvm E/RecyclerView: No adapter attached; skipping layout 2022-03-23 14:44:19.628 13773-13773/com.example.finalvm D/MainActivity: posts loaded from API 2022-03-23 14:44:19.729 13773-13800/com.example.finalvm D/EGL_emulation: eglMakeCurrent: 0xaf034d60: ver 2 0 (tinfo 0xaf039470) 2022-03-23 14:44:19.827 13773-13800/com.example.finalvm V/RenderScript: 0xb41a6e00 Launching thread(s), CPUs 4 2022-03-23 14:44:23.135 13773-13800/com.example.finalvm D/EGL_emulation: eglMakeCurrent: 0xaf034d60: ver 2 0 (tinfo 0xaf039470)