Null pointer exception during adding data on arrayadapter. getting error
E/AndroidRuntime(9233): FATAL EXCEPTION: main
E/AndroidRuntime(9233):java.lang.NullPointerException E/AndroidRuntime(9233): at co.adapter.TopicCustomDisplayArrayAdapter.getView(TopicCustomDisplayArrayAdapter.java:415)
E/AndroidRuntime(9233): at co.utils.TwoWayView.obtainView(TwoWayView.java:5599) E/AndroidRuntime(9233): at co.utils.TwoWayView.onMeasure(TwoWayView.java:3899) E/AndroidRuntime(9233): at android.view.View.measure(View.java:12773)
Doing this on my code:
private View convertView;
Holder holderText = null;
public TopicCustomDisplayArrayAdapter(Context context,
ArrayList<fieldModel> arrayList) {
super(context, R.layout.custom_display, arrayList);
mInflater = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
customTopicAd = arrayList;
mcontext = context;
options = new DisplayImageOptions.Builder().cacheInMemory(true)
.cacheOnDisc(true).considerExifParams(true)
.bitmapConfig(Bitmap.Config.RGB_565).build();
}
@Override
public View getView(final int position, View cv, ViewGroup parent) {
convertView = cv;
AdTypeString = customTopic.get(position).getAd_Type();
if (AdTypeString.equalsIgnoreCase("Text Ads")) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.text_view,
parent, false);
holderText = new Holder();
holderText.textRelativeLayout = (RelativeLayout) convertView
.findViewById(R.id.relativeTextAdView);
convertView.setTag(holderText);
} else {
holderText = (Holder) convertView.getTag();
}
int widthTextAd = Integer.parseInt(customTopicAd.get(position)
.getWidht());
int heightTextAd = Integer.parseInt(customTopicAd.get(position)
.getHeight();
holderText.textRelativeLayout.getLayoutParams().width = widthTextAd;
holderText.textRelativeLayout.getLayoutParams().height = heightTextAd;
} else if (AdTypeString.equalsIgnoreCase("Image Ads")) {
// display another layout
}
return convertView;
}
public static class Holder {
// Display Ads Resrouces
public RelativeLayout textRelativeLayout;
}
height and widht getting properly but could not set height and widht on relative layout. getting on this line:
holderText.textRelativeLayout.getLayoutParams().width = widthTextAd; holderText.textRelativeLayout.getLayoutParams().height = heightTextAd;
Any idea how to correction this error. here arraylist size is 5.