java - Android listview issues -
I am developing an Android application with my main activity, I will navigate to each other, Will show as. My problem lists a different adapter and lists the content in the list of contents.
My other activities are xml:
The activity is called: activity_doctor.
Back code:
increase the public activity of the public class {@Override protected void onCreate {Bundled savedinstenstate} {super.naught (the savedinstenstate); SetContentView (R.layout.activity_doctor); // Show button at the top of the action bar getActionBar () setDisplayHomeAsUpEnabled (true). ArrayList & LT; Doctor & gt; Docs = null; StrictMode.ThreadPolicy Policy = New StrictMode.ThreadPolicy.Builder (). PermitAll () Build (); StrictMode.setThreadPolicy (policy); Try {String Doctor = GetDoctorsFromServer (); Docs = Gate Doctor ListFrostler String (Doctor); } Grip (Exception E) {// TODO Auto generated blocking block e.printStackTrace (); } ListView myListView = New ListView (this); String [] docsair = new string [docs.size () + 1]; Int i = 0; For (Doctor D: Docs) {docs more [i] = d.getDoctorName (); I ++; } MyListView.setAdapter (New ArrayAdapter & lt; string & gt; (This, R.layout.activity_doctor, R.id.doctorslistview, docsArray)); // setListAdapter (new array adapter & lt; string & gt; (this, R. Lit activation_doc, docsair)); SetContentView (myListView); }
An error occurs when the last instruction is executed: setContentView (myListView);
Stack trace:
02-17 21: 51: 48.639: E / Android Random (24298): Fatal Exception: Main 02-17 21: 51: 48.639: E / Android Random (24298): Process: com.example.cabinetmedical.android, PID: 24298 02-17 21: 51: 48.639: E / AndroidRuntime (24,298): java.lang.NullPointerException 02-17 21: 51 : 48.639: E / AndroidRuntime (24,298): android.widget.ArrayAdapter.createViewFromResource (ArrayAdapter.java:394) from 02- 17 to 21: 51: 48.639: E / AndroidRuntime (24,298): 51 :: 48.639: E / AndroidRuntime (24,298): android.widget.ArrayAdapter.getView (ArrayAdapter.java:362) at 02-17 21 android.widget. AbsListView.obtainView (AbsListView.javacember452) 02-17 21: 51: 48.639: E / AndroidRuntime (24,298): android.widget.ListView.makeAndAddView (ListView.java:1891) on 02-17 21: 51: 48.639: E / Android Random (24298): Android.Windet.ListviewFillDown (ListView.java:792) 02-17 21: 51: 48.639: E / Android Time (24298): On One Thanks
This is not the way to do this, you are using the setContentView twice what is activty_doctors.xml inside? There should be a ListView item in which you will force it with getListView or findViewById.
Comments
Post a Comment