title: Rectifying a logcat error "Attempt to write to null array"
body: <p>I am writing a very Basic Home Launcher, I have made a class AppsInfoModel, a CustomAdapter and a GridView in AppsGridActivity.</p>
  
  <p>Here is my code for populating the adapter in Activity</p>
  
  <pre><code>    appsGrid = (GridView) findViewById(R.id.appsGrid);
      appsInfo = new AppsInfoModel(this);
      appsGrid.setAdapter(new CustomAdapter(this,appsInfo));
  </code></pre>
  
  <p>Here is adapter</p>
  
  <pre><code>public class CustomAdapter extends BaseAdapter {
  
  Context context;
  AppsInfoModel appInfo;
  CustomAdapter(Context context,AppsInfoModel appInfo) {
      this.context = context;
      this.appInfo = appInfo;
  }
  
  @Override
  public int getCount() {
      return appInfo.getSize();
  }
  
  @Override
  public Object getItem(int position) {
      return appInfo.getItem(position);
  }
  
  @Override
  public long getItemId(int position) {
      return position;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      if (convertView == null) {
          LayoutInflater inflater = ((Activity) context).getLayoutInflater();
          convertView = inflater.inflate(R.layout.single_grid, parent, false);
  
          ImageView icon = (ImageView) convertView.findViewById(R.id.app_icon);
          icon.setImageDrawable(appInfo.getIcon(position));
  
          TextView label = (TextView) convertView.findViewById(R.id.app_label);
          label.setText(appInfo.getLabel(position));
          return convertView;
      }
      else
          return convertView;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And Model class</p>
  
  <pre><code>public class AppsInfoModel {
  String label[];
  String name[];
  Drawable icon[];
  PackageManager pm;
  List&lt;ResolveInfo&gt; appsInfo;
  
  AppsInfoModel(Context context){
      pm=context.getPackageManager();
      appsInfo = pm.queryIntentActivities(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER), 0);
      for(int i=0;i&lt;appsInfo.size();i++){
          label[i]= (appsInfo.get(i).loadLabel(pm)).toString();//***This is where problem lies according to LogCat***
          name[i]= (appsInfo.get(i)).activityInfo.packageName;
          icon[i]=(appsInfo.get(i)).activityInfo.loadIcon(pm);
      }
  }
  
  Drawable getIcon(int i){
      return icon[i];
  }
  
  String getLabel(int i){
      return label[i];
  }
  
  String getPackageName(int i){
      return name[i];
  }
  int getSize(){
      return appsInfo.size();
  }
  
  public ResolveInfo getItem(int i) {
      return appsInfo.get(i);
  }
  }
  </code></pre>
  
  <p>And Here is the Logcat error</p>
  
  <pre><code> java.lang.RuntimeException: Unable to start activity ComponentInfo{example.home/example.home.AppsGridActivity}: java.lang.NullPointerException: Attempt to write to null array
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
          at android.app.ActivityThread.access$800(ActivityThread.java:144)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:135)
          at android.app.ActivityThread.main(ActivityThread.java:5221)
          at java.lang.reflect.Method.invoke(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:372)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
   Caused by: java.lang.NullPointerException: Attempt to write to null array
          at example.home.AppsInfoModel.&lt;init&gt;(AppsInfoModel.java:25)
          at example.home.AppsGridActivity.onCreate(AppsGridActivity.java:21)
          at android.app.Activity.performCreate(Activity.java:5933)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
              at android.app.ActivityThread.access$800(ActivityThread.java:144)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5221)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  </code></pre>
  
  <p>Why is it occuring?
  what is the problem with the logic or syntax.</p>