NullPointerException in while loop
<p>I want to calculate the total call duration of every contact in given period from call log, but I stuck with this NullPointerException in my while loop:</p>

<pre><code>Cursor c = cr.query(CallLog.Calls.CONTENT_URI, projection, selection, null, null);
            if(c.moveToFirst()){
                int[] duration = new int[c.getCount()];
                String[] name = new String[c.getCount()];

                do{
                    boolean w = false;
                    int y=0;
                    do{
                        if(name[y].equals("")){
                            name[y]=c.getString(c.getColumnIndex(CallLog.Calls.CACHED_NAME));
                            duration[y]+=Integer.parseInt(c.getString(c.getColumnIndex(CallLog.Calls.DURATION)));
                            w = true;
                        }else if(name[y].equals(c.getString(c.getColumnIndex(CallLog.Calls.CACHED_NAME)))){
                            duration[y]+=Integer.parseInt(c.getString(c.getColumnIndex(CallLog.Calls.DURATION)));
                            w = true;
                        }
                        y++;
                    }while(w);
            }
</code></pre>

<p>The error accurs in if statment where <code>if(name[y].equals(""))</code>
The cursors projection ant selection seems to work fine.</p>

<p>Here`s my stack trace:</p>

<pre><code>10-22 07:36:18.429: E/AndroidRuntime(27320): FATAL EXCEPTION: main
10-22 07:36:18.429: E/AndroidRuntime(27320): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dailyreports.ainius/com.dailyreports.ainius.ReportView}: java.lang.NullPointerException
10-22 07:36:18.429: E/AndroidRuntime(27320):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
10-22 07:36:18.429: E/AndroidRuntime(27320):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
10-22 07:36:18.429: E/AndroidRuntime(27320):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-22 07:36:18.429: E/AndroidRuntime(27320):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-22 07:36:18.429: E/AndroidRuntime(27320):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-22 07:36:18.429: E/AndroidRuntime(27320):    at android.os.Looper.loop(Looper.java:123)
10-22 07:36:18.429: E/AndroidRuntime(27320):    at android.app.ActivityThread.main(ActivityThread.java:3729)
10-22 07:36:18.429: E/AndroidRuntime(27320):    at java.lang.reflect.Method.invokeNative(Native Method)
10-22 07:36:18.429: E/AndroidRuntime(27320):    at java.lang.reflect.Method.invoke(Method.java:507)
10-22 07:36:18.429: E/AndroidRuntime(27320):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
10-22 07:36:18.429: E/AndroidRuntime(27320):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
10-22 07:36:18.429: E/AndroidRuntime(27320):    at dalvik.system.NativeStart.main(Native Method)
10-22 07:36:18.429: E/AndroidRuntime(27320): Caused by: java.lang.NullPointerException
10-22 07:36:18.429: E/AndroidRuntime(27320):    at com.dailyreports.ainius.DataProvider.getTotalCallDuration(DataProvider.java:1359)
10-22 07:36:18.429: E/AndroidRuntime(27320):    at com.dailyreports.ainius.DataProvider.getReportData(DataProvider.java:109)
10-22 07:36:18.429: E/AndroidRuntime(27320):    at com.dailyreports.ainius.ReportView.onCreate(ReportView.java:139)
10-22 07:36:18.429: E/AndroidRuntime(27320):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-22 07:36:18.429: E/AndroidRuntime(27320):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
10-22 07:36:18.429: E/AndroidRuntime(27320):    ... 11 more
</code></pre>

<p>Im sure its an easy one, but I just cant figure it out.</p>
