I have a listview that have 5 item in it if am trying to set error on the 4 th and 5th item .Then it is throwing a null pointer exception. Exception
08-22 13:34:49.523: E/AndroidRuntime(16952): FATAL EXCEPTION: main
08-22 13:34:49.523: E/AndroidRuntime(16952): java.lang.NullPointerException
08-22 13:34:49.523: E/AndroidRuntime(16952): at com.example.iweenflightbookingpage.MainActivity$1.onClick(MainActivity.java:116)
08-22 13:34:49.523: E/AndroidRuntime(16952): at android.view.View.performClick(View.java:4091)
08-22 13:34:49.523: E/AndroidRuntime(16952): at android.view.View$PerformClick.run(View.java:17072)
08-22 13:34:49.523: E/AndroidRuntime(16952): at android.os.Handler.handleCallback(Handler.java:615)
08-22 13:34:49.523: E/AndroidRuntime(16952): at android.os.Handler.dispatchMessage(Handler.java:92)
08-22 13:34:49.523: E/AndroidRuntime(16952): at android.os.Looper.loop(Looper.java:153)
08-22 13:34:49.523: E/AndroidRuntime(16952): at android.app.ActivityThread.main(ActivityThread.java:4987)
08-22 13:34:49.523: E/AndroidRuntime(16952): at java.lang.reflect.Method.invokeNative(Native Method)
08-22 13:34:49.523: E/AndroidRuntime(16952): at java.lang.reflect.Method.invoke(Method.java:511)
08-22 13:34:49.523: E/AndroidRuntime(16952): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
08-22 13:34:49.523: E/AndroidRuntime(16952): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
08-22 13:34:49.523: E/AndroidRuntime(16952): at dalvik.system.NativeStart.main(Native Method)
Code To set Error
click.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
allValues = myAdapter.getAllValues();
ArrayList<Integer> errorList = new ArrayList<Integer>();
for(int i = 0; i < allValues.length; i++){
for(int j=0;j<staticPasengerList.length;j++){
if(allValues[i] == staticPasengerList[j]){
Log.d("Lop Count", ""+allValues[i]+"="+staticPasengerList[j]);
// Add position to errorList
errorList.add(i);
}
}
}
myAdapter.setErrorList(errorList);
myAdapter.notifyDataSetChanged();
}
}
}
BaseAdapter Class
class data extends BaseAdapter {
String[] Title;
Activity activity;
public data (MainActivity mainActivity, String[] text) {
Title = text;
activity = mainActivity;
}
public String[] getAllValues() {
return Title;
}
public int getCount() {
// TODO Auto-generated method stub
return Title.length;
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = activity.getLayoutInflater();
View row ;
row = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
TextView title;
title = (TextView) row.findViewById(android.R.id.text1);
title.setText(Title[position]);
return (row);
}
This exception is occuring in case of 4 and 5 will be the value of i. Please help me to resolve the issue