Setting a custom Adapter for a ListView causes my app to jump to the previous activity












-1















When I try to populate my listview with my custom adapter or object of my custom class, the application jumps back to the previous activity.

I tried to debug, but I can't find the row that causes this behavior.

Maybe there's something with the layout that at the moment to to be inflated and drawn encounters some problem.



ACTIVITY CODE



try {
JSONObject obj = new JSONObject(response);

String objservice = obj.getString("service");
String objstatuCode = obj.getString("status-code");
String objdescription = obj.getString("status-description");

JSONObject result = obj.getJSONObject("result");


JSONArray cronologie = result.getJSONArray("dettaglioAttivita");


inputItems = new ArrayList<DTOLibrettoCronologia>();


for (int i = 0; i < cronologie.length(); i++) {


JSONObject row = cronologie.getJSONObject(i);


DTOLibrettoCronologia tmp = new DTOLibrettoCronologia("s", "s", "s", "s", "s", "s", "s");
inputItems.add(tmp);

}


} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
}

librettoCronologiaAdapter adapter = new librettoCronologiaAdapter(getApplicationContext(),
R.layout.libretto_cronologia, inputItems);


listView = (ListView) findViewById(R.id.cronologia_listview);
listView.setAdapter(adapter);
listView.setSmoothScrollbarEnabled(true);


XML ELEMENT CODE



<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/libretto_cronologia_element"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:background="@color/transparent">
<!-- primary wrapper -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/transparent">

<!--image -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/transparent"
android:layout_marginTop="5dp"
android:layout_marginLeft="16dp">
<ImageView
android:id="@+id/cronologiaState"
android:layout_width="36dp"
android:layout_height="40dp"
android:src="@drawable/check_cronologia_fail"/>
</LinearLayout>

<!--text -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/transparent"
android:paddingLeft="8dp"
android:paddingTop="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data Appello: "/>
<TextView
android:id="@+id/cronologiaDataAppello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>


<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tipo: "/>
<TextView
android:id="@+id/cronologiaTipo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Voto/Giudizio: "/>
<TextView
android:id="@+id/cronologiaVoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stato: "/>
<TextView
android:id="@+id/cronologiaStato"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data Verb: "/>
<TextView
android:id="@+id/cronologiaVerb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Superato: "/>
<TextView
android:id="@+id/cronologiaSuperato"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

</LinearLayout>



</LinearLayout>
</RelativeLayout>


XMLACTIVITY CODE



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cronologia_materia"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|bottom">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<!-- TOP BAR -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/colorPrimary"
android:padding="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="cronologia esami per"
android:textSize="13dp"/>
<TextView
android:id="@+id/nomeMateria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-"
android:textSize="18dp"/>
</LinearLayout>



<!-- general info -->
<LinearLayout
android:id="@+id/recapWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:orientation="vertical"
android:padding="20dp">



<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/annoCorso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Anno di Corso:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/annoCorsoValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tipologia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tipologia d'esame:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/tipologiaValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/corso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Corso di Studio:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/corsoValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/dataSperamento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data di Superamento:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/dataSperamentoValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/votoFinale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Voto Finale"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/votoFinaleValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/peso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Peso:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/pesoValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/Valutazione"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Valutazione:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/ValutazioneValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


</LinearLayout>



<!-- LISTVIEW -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/transparent"
android:padding="20dp">

<ListView
android:id="@+id/cronologia_listview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>


</LinearLayout>





</LinearLayout>
</FrameLayout>


CUSTOM ADAPTER CODE



public class librettoCronologiaAdapter extends ArrayAdapter<DTOLibrettoCronologia> {

Context context;
int rand = 0;

public librettoCronologiaAdapter(Context context, int risorsaId,
List<DTOLibrettoCronologia> items) {
super(context, risorsaId, items);
this.context = context;
}


//metodo getView --> ritorna la view da inserire nella ListView

public View getView(int position, View convertView, ViewGroup parent) {

//controllo se c'è gia un layout
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

DTOLibrettoCronologia content = getItem(position);

Toast.makeText(getContext(), "adapter", Toast.LENGTH_SHORT).show();




return convertView;
}


LOGCAT



FATAL EXCEPTION: main
Process: design.ubris.myuni, PID: 14189
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference
at android.widget.AbsListView.obtainView(AbsListView.java:2436)
at android.widget.ListView.makeAndAddView(ListView.java:1986)
at android.widget.ListView.fillDown(ListView.java:709)
at android.widget.ListView.fillFromTop(ListView.java:770)
at android.widget.ListView.layoutChildren(ListView.java:1749)
at android.widget.AbsListView.onLayout(AbsListView.java:2210)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1762)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1606)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1515)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1762)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1606)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1515)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1762)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1606)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1515)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:774)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2519)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2234)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1372)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6774)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:926)
at android.view.Choreographer.doCallbacks(Choreographer.java:735)
at android.view.Choreographer.doFrame(Choreographer.java:667)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:912)
at android.os.Handler.handleCallback(Handler.java:761)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)









share|improve this question

























  • Add your custom adapter code and logcat.

    – Danger
    Nov 14 '18 at 10:14
















-1















When I try to populate my listview with my custom adapter or object of my custom class, the application jumps back to the previous activity.

I tried to debug, but I can't find the row that causes this behavior.

Maybe there's something with the layout that at the moment to to be inflated and drawn encounters some problem.



ACTIVITY CODE



try {
JSONObject obj = new JSONObject(response);

String objservice = obj.getString("service");
String objstatuCode = obj.getString("status-code");
String objdescription = obj.getString("status-description");

JSONObject result = obj.getJSONObject("result");


JSONArray cronologie = result.getJSONArray("dettaglioAttivita");


inputItems = new ArrayList<DTOLibrettoCronologia>();


for (int i = 0; i < cronologie.length(); i++) {


JSONObject row = cronologie.getJSONObject(i);


DTOLibrettoCronologia tmp = new DTOLibrettoCronologia("s", "s", "s", "s", "s", "s", "s");
inputItems.add(tmp);

}


} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
}

librettoCronologiaAdapter adapter = new librettoCronologiaAdapter(getApplicationContext(),
R.layout.libretto_cronologia, inputItems);


listView = (ListView) findViewById(R.id.cronologia_listview);
listView.setAdapter(adapter);
listView.setSmoothScrollbarEnabled(true);


XML ELEMENT CODE



<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/libretto_cronologia_element"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:background="@color/transparent">
<!-- primary wrapper -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/transparent">

<!--image -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/transparent"
android:layout_marginTop="5dp"
android:layout_marginLeft="16dp">
<ImageView
android:id="@+id/cronologiaState"
android:layout_width="36dp"
android:layout_height="40dp"
android:src="@drawable/check_cronologia_fail"/>
</LinearLayout>

<!--text -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/transparent"
android:paddingLeft="8dp"
android:paddingTop="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data Appello: "/>
<TextView
android:id="@+id/cronologiaDataAppello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>


<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tipo: "/>
<TextView
android:id="@+id/cronologiaTipo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Voto/Giudizio: "/>
<TextView
android:id="@+id/cronologiaVoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stato: "/>
<TextView
android:id="@+id/cronologiaStato"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data Verb: "/>
<TextView
android:id="@+id/cronologiaVerb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Superato: "/>
<TextView
android:id="@+id/cronologiaSuperato"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

</LinearLayout>



</LinearLayout>
</RelativeLayout>


XMLACTIVITY CODE



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cronologia_materia"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|bottom">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<!-- TOP BAR -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/colorPrimary"
android:padding="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="cronologia esami per"
android:textSize="13dp"/>
<TextView
android:id="@+id/nomeMateria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-"
android:textSize="18dp"/>
</LinearLayout>



<!-- general info -->
<LinearLayout
android:id="@+id/recapWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:orientation="vertical"
android:padding="20dp">



<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/annoCorso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Anno di Corso:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/annoCorsoValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tipologia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tipologia d'esame:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/tipologiaValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/corso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Corso di Studio:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/corsoValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/dataSperamento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data di Superamento:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/dataSperamentoValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/votoFinale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Voto Finale"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/votoFinaleValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/peso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Peso:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/pesoValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/Valutazione"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Valutazione:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/ValutazioneValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


</LinearLayout>



<!-- LISTVIEW -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/transparent"
android:padding="20dp">

<ListView
android:id="@+id/cronologia_listview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>


</LinearLayout>





</LinearLayout>
</FrameLayout>


CUSTOM ADAPTER CODE



public class librettoCronologiaAdapter extends ArrayAdapter<DTOLibrettoCronologia> {

Context context;
int rand = 0;

public librettoCronologiaAdapter(Context context, int risorsaId,
List<DTOLibrettoCronologia> items) {
super(context, risorsaId, items);
this.context = context;
}


//metodo getView --> ritorna la view da inserire nella ListView

public View getView(int position, View convertView, ViewGroup parent) {

//controllo se c'è gia un layout
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

DTOLibrettoCronologia content = getItem(position);

Toast.makeText(getContext(), "adapter", Toast.LENGTH_SHORT).show();




return convertView;
}


LOGCAT



FATAL EXCEPTION: main
Process: design.ubris.myuni, PID: 14189
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference
at android.widget.AbsListView.obtainView(AbsListView.java:2436)
at android.widget.ListView.makeAndAddView(ListView.java:1986)
at android.widget.ListView.fillDown(ListView.java:709)
at android.widget.ListView.fillFromTop(ListView.java:770)
at android.widget.ListView.layoutChildren(ListView.java:1749)
at android.widget.AbsListView.onLayout(AbsListView.java:2210)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1762)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1606)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1515)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1762)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1606)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1515)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1762)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1606)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1515)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:774)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2519)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2234)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1372)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6774)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:926)
at android.view.Choreographer.doCallbacks(Choreographer.java:735)
at android.view.Choreographer.doFrame(Choreographer.java:667)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:912)
at android.os.Handler.handleCallback(Handler.java:761)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)









share|improve this question

























  • Add your custom adapter code and logcat.

    – Danger
    Nov 14 '18 at 10:14














-1












-1








-1








When I try to populate my listview with my custom adapter or object of my custom class, the application jumps back to the previous activity.

I tried to debug, but I can't find the row that causes this behavior.

Maybe there's something with the layout that at the moment to to be inflated and drawn encounters some problem.



ACTIVITY CODE



try {
JSONObject obj = new JSONObject(response);

String objservice = obj.getString("service");
String objstatuCode = obj.getString("status-code");
String objdescription = obj.getString("status-description");

JSONObject result = obj.getJSONObject("result");


JSONArray cronologie = result.getJSONArray("dettaglioAttivita");


inputItems = new ArrayList<DTOLibrettoCronologia>();


for (int i = 0; i < cronologie.length(); i++) {


JSONObject row = cronologie.getJSONObject(i);


DTOLibrettoCronologia tmp = new DTOLibrettoCronologia("s", "s", "s", "s", "s", "s", "s");
inputItems.add(tmp);

}


} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
}

librettoCronologiaAdapter adapter = new librettoCronologiaAdapter(getApplicationContext(),
R.layout.libretto_cronologia, inputItems);


listView = (ListView) findViewById(R.id.cronologia_listview);
listView.setAdapter(adapter);
listView.setSmoothScrollbarEnabled(true);


XML ELEMENT CODE



<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/libretto_cronologia_element"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:background="@color/transparent">
<!-- primary wrapper -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/transparent">

<!--image -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/transparent"
android:layout_marginTop="5dp"
android:layout_marginLeft="16dp">
<ImageView
android:id="@+id/cronologiaState"
android:layout_width="36dp"
android:layout_height="40dp"
android:src="@drawable/check_cronologia_fail"/>
</LinearLayout>

<!--text -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/transparent"
android:paddingLeft="8dp"
android:paddingTop="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data Appello: "/>
<TextView
android:id="@+id/cronologiaDataAppello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>


<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tipo: "/>
<TextView
android:id="@+id/cronologiaTipo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Voto/Giudizio: "/>
<TextView
android:id="@+id/cronologiaVoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stato: "/>
<TextView
android:id="@+id/cronologiaStato"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data Verb: "/>
<TextView
android:id="@+id/cronologiaVerb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Superato: "/>
<TextView
android:id="@+id/cronologiaSuperato"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

</LinearLayout>



</LinearLayout>
</RelativeLayout>


XMLACTIVITY CODE



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cronologia_materia"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|bottom">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<!-- TOP BAR -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/colorPrimary"
android:padding="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="cronologia esami per"
android:textSize="13dp"/>
<TextView
android:id="@+id/nomeMateria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-"
android:textSize="18dp"/>
</LinearLayout>



<!-- general info -->
<LinearLayout
android:id="@+id/recapWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:orientation="vertical"
android:padding="20dp">



<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/annoCorso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Anno di Corso:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/annoCorsoValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tipologia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tipologia d'esame:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/tipologiaValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/corso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Corso di Studio:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/corsoValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/dataSperamento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data di Superamento:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/dataSperamentoValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/votoFinale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Voto Finale"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/votoFinaleValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/peso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Peso:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/pesoValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/Valutazione"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Valutazione:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/ValutazioneValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


</LinearLayout>



<!-- LISTVIEW -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/transparent"
android:padding="20dp">

<ListView
android:id="@+id/cronologia_listview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>


</LinearLayout>





</LinearLayout>
</FrameLayout>


CUSTOM ADAPTER CODE



public class librettoCronologiaAdapter extends ArrayAdapter<DTOLibrettoCronologia> {

Context context;
int rand = 0;

public librettoCronologiaAdapter(Context context, int risorsaId,
List<DTOLibrettoCronologia> items) {
super(context, risorsaId, items);
this.context = context;
}


//metodo getView --> ritorna la view da inserire nella ListView

public View getView(int position, View convertView, ViewGroup parent) {

//controllo se c'è gia un layout
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

DTOLibrettoCronologia content = getItem(position);

Toast.makeText(getContext(), "adapter", Toast.LENGTH_SHORT).show();




return convertView;
}


LOGCAT



FATAL EXCEPTION: main
Process: design.ubris.myuni, PID: 14189
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference
at android.widget.AbsListView.obtainView(AbsListView.java:2436)
at android.widget.ListView.makeAndAddView(ListView.java:1986)
at android.widget.ListView.fillDown(ListView.java:709)
at android.widget.ListView.fillFromTop(ListView.java:770)
at android.widget.ListView.layoutChildren(ListView.java:1749)
at android.widget.AbsListView.onLayout(AbsListView.java:2210)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1762)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1606)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1515)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1762)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1606)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1515)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1762)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1606)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1515)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:774)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2519)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2234)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1372)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6774)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:926)
at android.view.Choreographer.doCallbacks(Choreographer.java:735)
at android.view.Choreographer.doFrame(Choreographer.java:667)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:912)
at android.os.Handler.handleCallback(Handler.java:761)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)









share|improve this question
















When I try to populate my listview with my custom adapter or object of my custom class, the application jumps back to the previous activity.

I tried to debug, but I can't find the row that causes this behavior.

Maybe there's something with the layout that at the moment to to be inflated and drawn encounters some problem.



ACTIVITY CODE



try {
JSONObject obj = new JSONObject(response);

String objservice = obj.getString("service");
String objstatuCode = obj.getString("status-code");
String objdescription = obj.getString("status-description");

JSONObject result = obj.getJSONObject("result");


JSONArray cronologie = result.getJSONArray("dettaglioAttivita");


inputItems = new ArrayList<DTOLibrettoCronologia>();


for (int i = 0; i < cronologie.length(); i++) {


JSONObject row = cronologie.getJSONObject(i);


DTOLibrettoCronologia tmp = new DTOLibrettoCronologia("s", "s", "s", "s", "s", "s", "s");
inputItems.add(tmp);

}


} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
}

librettoCronologiaAdapter adapter = new librettoCronologiaAdapter(getApplicationContext(),
R.layout.libretto_cronologia, inputItems);


listView = (ListView) findViewById(R.id.cronologia_listview);
listView.setAdapter(adapter);
listView.setSmoothScrollbarEnabled(true);


XML ELEMENT CODE



<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/libretto_cronologia_element"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:background="@color/transparent">
<!-- primary wrapper -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/transparent">

<!--image -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/transparent"
android:layout_marginTop="5dp"
android:layout_marginLeft="16dp">
<ImageView
android:id="@+id/cronologiaState"
android:layout_width="36dp"
android:layout_height="40dp"
android:src="@drawable/check_cronologia_fail"/>
</LinearLayout>

<!--text -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/transparent"
android:paddingLeft="8dp"
android:paddingTop="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data Appello: "/>
<TextView
android:id="@+id/cronologiaDataAppello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>


<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tipo: "/>
<TextView
android:id="@+id/cronologiaTipo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Voto/Giudizio: "/>
<TextView
android:id="@+id/cronologiaVoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stato: "/>
<TextView
android:id="@+id/cronologiaStato"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data Verb: "/>
<TextView
android:id="@+id/cronologiaVerb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Superato: "/>
<TextView
android:id="@+id/cronologiaSuperato"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="content"/>
</LinearLayout>

</LinearLayout>



</LinearLayout>
</RelativeLayout>


XMLACTIVITY CODE



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cronologia_materia"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|bottom">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<!-- TOP BAR -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/colorPrimary"
android:padding="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="cronologia esami per"
android:textSize="13dp"/>
<TextView
android:id="@+id/nomeMateria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-"
android:textSize="18dp"/>
</LinearLayout>



<!-- general info -->
<LinearLayout
android:id="@+id/recapWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:orientation="vertical"
android:padding="20dp">



<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/annoCorso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Anno di Corso:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/annoCorsoValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tipologia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tipologia d'esame:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/tipologiaValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/corso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Corso di Studio:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/corsoValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/dataSperamento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data di Superamento:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/dataSperamentoValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/votoFinale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Voto Finale"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/votoFinaleValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/peso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Peso:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/pesoValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/Valutazione"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Valutazione:"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/ValutazioneValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>


</LinearLayout>



<!-- LISTVIEW -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/transparent"
android:padding="20dp">

<ListView
android:id="@+id/cronologia_listview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>


</LinearLayout>





</LinearLayout>
</FrameLayout>


CUSTOM ADAPTER CODE



public class librettoCronologiaAdapter extends ArrayAdapter<DTOLibrettoCronologia> {

Context context;
int rand = 0;

public librettoCronologiaAdapter(Context context, int risorsaId,
List<DTOLibrettoCronologia> items) {
super(context, risorsaId, items);
this.context = context;
}


//metodo getView --> ritorna la view da inserire nella ListView

public View getView(int position, View convertView, ViewGroup parent) {

//controllo se c'è gia un layout
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

DTOLibrettoCronologia content = getItem(position);

Toast.makeText(getContext(), "adapter", Toast.LENGTH_SHORT).show();




return convertView;
}


LOGCAT



FATAL EXCEPTION: main
Process: design.ubris.myuni, PID: 14189
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference
at android.widget.AbsListView.obtainView(AbsListView.java:2436)
at android.widget.ListView.makeAndAddView(ListView.java:1986)
at android.widget.ListView.fillDown(ListView.java:709)
at android.widget.ListView.fillFromTop(ListView.java:770)
at android.widget.ListView.layoutChildren(ListView.java:1749)
at android.widget.AbsListView.onLayout(AbsListView.java:2210)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1762)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1606)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1515)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1762)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1606)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1515)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1762)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1606)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1515)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:774)
at android.view.View.layout(View.java:17702)
at android.view.ViewGroup.layout(ViewGroup.java:5631)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2519)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2234)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1372)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6774)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:926)
at android.view.Choreographer.doCallbacks(Choreographer.java:735)
at android.view.Choreographer.doFrame(Choreographer.java:667)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:912)
at android.os.Handler.handleCallback(Handler.java:761)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)






android listview adapter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 10:39







Giorgio Cafiso

















asked Nov 14 '18 at 9:57









Giorgio CafisoGiorgio Cafiso

418




418













  • Add your custom adapter code and logcat.

    – Danger
    Nov 14 '18 at 10:14



















  • Add your custom adapter code and logcat.

    – Danger
    Nov 14 '18 at 10:14

















Add your custom adapter code and logcat.

– Danger
Nov 14 '18 at 10:14





Add your custom adapter code and logcat.

– Danger
Nov 14 '18 at 10:14












1 Answer
1






active

oldest

votes


















0














simply adding this to the adapter getView method:



    if (convertView == null) {
convertView = mInflater.inflate(R.layout.libretto_cronologia, null);
}


:D :D






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297411%2fsetting-a-custom-adapter-for-a-listview-causes-my-app-to-jump-to-the-previous-ac%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    simply adding this to the adapter getView method:



        if (convertView == null) {
    convertView = mInflater.inflate(R.layout.libretto_cronologia, null);
    }


    :D :D






    share|improve this answer




























      0














      simply adding this to the adapter getView method:



          if (convertView == null) {
      convertView = mInflater.inflate(R.layout.libretto_cronologia, null);
      }


      :D :D






      share|improve this answer


























        0












        0








        0







        simply adding this to the adapter getView method:



            if (convertView == null) {
        convertView = mInflater.inflate(R.layout.libretto_cronologia, null);
        }


        :D :D






        share|improve this answer













        simply adding this to the adapter getView method:



            if (convertView == null) {
        convertView = mInflater.inflate(R.layout.libretto_cronologia, null);
        }


        :D :D







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 13:51









        Giorgio CafisoGiorgio Cafiso

        418




        418
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297411%2fsetting-a-custom-adapter-for-a-listview-causes-my-app-to-jump-to-the-previous-ac%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Lugert, Oklahoma