I define this String Array:
String[] mCountryList = new String[200];
and fill up the variable with JSON data, and when I use that variable with an ArrayAdapter
:
ArrayAdapter<String> myAdaptor = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, mCountryList);
I get this error:
java.lang.NullPointerException
I think the String array mCountryList
can have null values. For example:
mCountryList[0]="x";
mCountryList[1]="x";
mCountryList[2]=null;
How can I solve this?
The stacktrace I get is:
2459-2459/com.example.behzad.behmytour E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.behzad.behmytour, PID: 2459 java.lang.NullPointerException at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394) at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362) at android.widget.AbsListView.obtainView(AbsListView.java:2263) at android.widget.ListView.makeAndAddView(ListView.java:1790) at android.widget.ListView.fillDown(ListView.java:691) at android.widget.ListView.fillFromTop(ListView.java:752) at android.widget.ListView.layoutChildren(ListView.java:1630) at android.widget.AbsListView.onLayout(AbsListView.java:2091) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631)
expanded stacktrace
and showing the line you are getting the error – hrskrs Mar 16 '15 at 15:30mCountryList
, then further down it'smCountr
, what is it now? And "null" is a String, that won't give you an NPE. – ci_ Mar 16 '15 at 15:31