I'm getting a Nullpointerexception in my custom ArrayAdapter in my App. I do not know why a Nullpointer is raised here. And i can not reproduce this exception. The exception did not appear a long time and i have no code changes, so this makes it even more strange. The code is:
private class MyAdapter<T> extends ArrayAdapter<String> {
private Map<String, String> selectedDevices;
public MyAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
BluetoothDbAdapter dbHelper = new BluetoothDbAdapter(context);
dbHelper.open();
selectedDevices = dbHelper.fetchAllDevicesAsMap();
dbHelper.close();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
CheckedTextView item = (CheckedTextView) view;
CharSequence text = item.getText();
if (selectedDevices.values().contains(text)) {
item.setChecked(true);
}
return item;
}
}
The Exception is raised in getView method in the first line. I have debugged my App and called super.getView with null parameters but no Nullpointerexception was raised, so it seemes that super have been null, but how can this be??? The StackTrace is:
java.lang.NullPointerException at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:355) at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323) at de.hartig.abt.activity.BluetoothDeviceList$MyAdapter.getView(BluetoothDeviceList.java:140) at android.widget.AbsListView.obtainView(AbsListView.java:1408) at android.widget.ListView.makeAndAddView(ListView.java:1727) at android.widget.ListView.fillDown(ListView.java:652) at android.widget.ListView.fillFromTop(ListView.java:709) at android.widget.ListView.layoutChildren(ListView.java:1580) at android.widget.AbsListView.onLayout(AbsListView.java:1240) at android.view.View.layout(View.java:7057) at android.widget.FrameLayout.onLayout(FrameLayout.java:333) at android.view.View.layout(View.java:7057) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125) at android.widget.LinearLayout.onLayout(LinearLayout.java:1042) at android.view.View.layout(View.java:7057) at android.widget.FrameLayout.onLayout(FrameLayout.java:333) at android.view.View.layout(View.java:7057) at android.view.ViewRoot.performTraversals(ViewRoot.java:1045) at android.view.ViewRoot.handleMessage(ViewRoot.java:1727) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:4680) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) at dalvik.system.NativeStart.main(Native Method)
Does any body know how i can solve this problem? Thanks for help!!!