If I assign a value to my recyclerview. I have a method "listRe", where I get the idpublication and send it to another method "ListFile2" where I want to obtain data from each idpublication.
Basically I want to put a recyclerview into another recyclerview.
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setAdapter(android.support.v7.widget.RecyclerView$Adapter)' on a null object reference at com.dese.diario.DetailPublication$18.onResponse(Unknown Source) at com.dese.diario.DetailPublication$18.onResponse(Unknown Source) at com.android.volley.toolbox.StringRequest.b(Unknown Source) at com.android.volley.toolbox.StringRequest.a(Unknown Source) at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(Unknown Source) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6123) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
I get ID
public void listarRe( final String pa){
RequestQueue queue = Volley.newRequestQueue(DetailPublication.this);
StringRequest stringRequest = new StringRequest(Request.Method.GET, urlListRepublication,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//JSONArray jsonArray = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
try {
listRepublicaciones = new ArrayList<>();
JSONArray jsonarray = new JSONArray(response);
for (int i = 0; i < jsonarray.length(); i++) {
JSONObject jsonobject = jsonarray.getJSONObject(i);
listRepublicaciones.add(new com.dese.diario.Objects.RePublication(
jsonobject.getString("padre"),
jsonobject.getString("idpublicacion"),
jsonobject.getString("foto"),
jsonobject.getString("observaciones"),
jsonobject.getString("titulo"),
jsonobject.getString("nombre"),
jsonobject.getString("idusuario"),
jsonobject.getString("analisis"),
jsonobject.getString("evaluacion"),
jsonobject.getString("conclusion"),
jsonobject.getString("token"),
jsonobject.getString("planaccion"),
jsonobject.getString("sentimiento")));
/* HashSet hs = new HashSet();
hs.addAll(listRepublicaciones);
listRepublicaciones.clear();*/
adapter = new Adapter_RePubication(listRepublicaciones,DetailPublication.this);
recyclerView.setAdapter(adapter);
// Toast.makeText(DetailPublication.this, "ide re"+jsonobject.getString("idpublicacion").toString(), Toast.LENGTH_LONG).show();
//& System.out.println(listRepublicaciones);
}
} catch (JSONException e) {
Log.e("DetailPublication", "Error +->" + e);
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Horror", "Response--->"+error);
}
}
) {
/**
* Passing some request headers
*/
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("idpublicacion", pa);
headers.put("Content-Type", "application/x-www-form-urlencoded");
return headers;
}
};
queue.add(stringRequest);
}
I send the Id
public void listarFile2( final String ide){
RequestQueue queue = Volley.newRequestQueue(DetailPublication.this);
StringRequest stringRequest = new StringRequest(Request.Method.GET,getFilesList ,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Toast.makeText(DetailPublication.this,"IDENTF"+ide, Toast.LENGTH_LONG).show(); // paths = new ArrayList<>();
//JSONArray jsonArray = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
try {
JSONArray jsonarray = new JSONArray(response);
/// Toast.makeText(DetailPublication.this,"JSON LENGHT--"+jsonarray.length(), Toast.LENGTH_LONG).show(); // paths = new ArrayList<>();
for (int i = 0; i < jsonarray.length(); i++) {
JSONObject jsonobject = jsonarray.getJSONObject(i);
String file=jsonobject.getString("descripcion");
String idre= jsonobject.getString("idpublicacion");
filename.add(file);
Toast.makeText(DetailPublication.this,"IDEPU"+idre+ "Archivos"+ file , Toast.LENGTH_LONG).show(); // paths = new ArrayList<>();
ia = new Adapter_File(filename, DetailPublication.this);
rvItemFeed.setAdapter(ia);
lyContentImagenDetailF.setVisibility(View.VISIBLE);
rvItemFeed.setItemAnimator(new DefaultItemAnimator());
rvItemFeed.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
// }
}
} catch (JSONException e) {
Log.e("Detail Publicacion", "Problema con" + e);
Toast.makeText(DetailPublication.this, e.toString(), Toast.LENGTH_LONG).show(); // paths = new ArrayList<>();
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Horror", "Response--->"+error);
}
}
) {
/**
* Passing some request headers
*/
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("idpublicacion", ide);
//headers.put("Content-Type", "application/x-www-form-urlencoded");
return headers;
}
};
queue.add(stringRequest);
}
XML LAYOUT (listarRe)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerRepost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:overScrollMode="never"
tools:listitem="@layout/item_repost" />
</LinearLayout>
XML LAYOUT 2 (listFile2)
<LinearLayout
android:id="@+id/lyContentImagenDetailF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:background="?colorAccent" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rvItemFeed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_span="3"
tools:listitem="@layout/item_file" />
</LinearLayout>