Q:

Adding addFooterView to Listview in Activity leads null pointer exception

Hello I'm using ASYNC task to parse data from json and listing it in to an activity.  However it works fine without the addFooterView.  When I try to add it, it gives me null pointer exception. 
    public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState); 
new FilesTask(baseurl, true).execute(); 
        footerView = getLayoutInflater().inflate(R.layout.listview_footer, null); }

@Override
        protected void onPreExecute() {
            if (isLoading){
                this.cancel(true);
            } else {
                isLoading = true;
            }
            if (initialload){
                pDialog = (RelativeLayout) ll.findViewById(R.id.progressBarHolder);

                if (pDialog.getVisibility() == View. GONE) {
                    pDialog.setVisibility(View. VISIBLE);
                    feedListView.setVisibility(View. GONE);
                }

                if (null ! = feedList){
                    feedList.clear();
                }
                if (null ! = feedListView){
                    feedListView.setAdapter(null);
                }
                if (Build. VERSION.SDK_INT < Build. VERSION_CODES.KITKAT) {
                    feedListView.addFooterView(footerView);
                }
            } else {
                feedListView.addFooterView(footerView);
            }
        }

        @Override
        protected void onPostExecute(Void result) {
            if (null ! = feedList) {
                //set adapter
                updateList(initialload);

                if (pDialog.getVisibility() == View. VISIBLE) {
                    pDialog.setVisibility(View. GONE);
                   feedListView.setVisibility(View. VISIBLE);

                   //    Helper.revealView(feedListView,ll);
                    if (Build. VERSION.SDK_INT < Build. VERSION_CODES.KITKAT) {
                        feedListView.addFooterView(footerView);
                    }
                } else if(footerView.getVisibility()== View. VISIBLE) {
                    feedListView.addFooterView(footerView);
                }

            }else{                                      // else feedList is empty

                pDialog.setVisibility(View. GONE);
            }

            isLoading = false;
        }

For reference
public void updateList(boolean initialload) {
        if (initialload){
            feedListAdapter = new CustomListAdapter(getApplicationContext(), 0, feedList);
            feedListView.setAdapter(feedListAdapter);
        } else {
            feedListAdapter.addAll(feedList);
            feedListAdapter.notifyDataSetChanged();
        }
    }

Here I have pasted the onPreExecute and postexecute.  Please advice me if I do anything wrong here.  Error occures at
if (Build. VERSION.SDK_INT < Build. VERSION_CODES.KITKAT) {
                        feedListView.addFooterView(footerView);
                    }

931-931/com.example E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang. RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.search. SearchActivity}: java.lang. NullPointerException
            at android.app. ActivityThread.performLaunchActivity(ActivityThread.java:2180)
            at android.app. ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app. ActivityThread.access$600(ActivityThread.java:141)
            at android.app. ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os. Handler.dispatchMessage(Handler.java:99)
            at android.os. Looper.loop(Looper.java:137)
            at android.app. ActivityThread.main(ActivityThread.java:5041)
            at java.lang.reflect. Method.invokeNative(Native Method)
            at java.lang.reflect. Method.invoke(Method.java:511)
            at com.android.internal.os. ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os. ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system. NativeStart.main(Native Method)
     Caused by: java.lang. NullPointerException
            at com.example.search. SearchActivity$DownloadFilesTask.onPreExecute(SearchActivity.java:198)
            at android.os. AsyncTask.executeOnExecutor(AsyncTask.java:586)
            at android.os. AsyncTask.execute(AsyncTask.java:534)
            at com.example.search. SearchActivity.onCreate(SearchActivity.java:105)
            at android.app. Activity.performCreate(Activity.java:5104)
            at android.app. Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
            at android.app. ActivityThread.performLaunchActivity(ActivityThread.java:2144)
            at android.app. ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app. ActivityThread.access$600(ActivityThread.java:141)
            at android.app. ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os. Handler.dispatchMessage(Handler.java:99)
            at android.os. Looper.loop(Looper.java:137)
            at android.app. ActivityThread.main(ActivityThread.java:5041)
            at java.lang.reflect. Method.invokeNative(Native Method)
            at java.lang.reflect. Method.invoke(Method.java:511)
            at com.android.internal.os. ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os. ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system. NativeStart.main(Native Method)

A:

Here I have to initialize listView before addFooterView. 
First initialize
footerView = getLayoutInflater().inflate(R.layout.listview_footer, null);

then
new FilesTask(baseurl, true).execute();

FilesTask(baseurl, true).execute(); will execute the remaining part of set adapter. 
Actually This kind of error occurs SDK below KITKAT.  solution is 
1.  TO initialize listview,footerView 
2.Do the remaining ASNYC Task

