title: Load data on listview
body: <p>I want to load data to listview through an intermediate class, I transmit data through the constructor. but in the data load process encounters an error that I can not solve, expect people to help me.</p>
  
  <p>Class loadListview</p>
  
  <pre><code>public class LoadListView {
  private Context mContext = null;
  ArrayList&lt;String&gt; phonenumberArray = new ArrayList&lt;String&gt;();
  ArrayList&lt;String&gt; codeInvoiceArray = new ArrayList&lt;String&gt;();
  ArrayList&lt;String&gt; nameArray = new ArrayList&lt;String&gt;();
  ArrayList&lt;String&gt; addressArray = new ArrayList&lt;String&gt;();
  ArrayList&lt;String&gt; urlArray = new ArrayList&lt;String&gt;();
  ListView listview=(ListView)((Activity)mContext).findViewById(R.id.listView1);
  String name,phonenumber,address,url,code,iddelivery;
  
  public LoadListView(Context mContext, String name,String phone,String address,String url,String code, String ID)
  {
      this.mContext=mContext;
      this.name=name;
      this.phonenumber=phone;
      this.code=code;
      this.address=address;
      this.url=url;
      this.iddelivery=ID;
  }
  
  
  // Xóa các item trong mảng để tránh sự trùng lặp
  public void clearArray()
  {
      codeInvoiceArray.clear();
      nameArray.clear();
      phonenumberArray.clear();
      addressArray.clear();
      urlArray.clear();
  }
  
  // load dữ liệu lên listview
  public void loaddatalistview()
  {
      clearArray();
      phonenumberArray.add(phonenumber);
      codeInvoiceArray.add(code);
      nameArray.add(name);
      addressArray.add(address);
      urlArray.add(url);
      listview.setAdapter(new DataAdapter(mContext, codeInvoiceArray
              .toArray(new String[codeInvoiceArray.size()]), nameArray
              .toArray(new String[nameArray.size()]), phonenumberArray
              .toArray(new String[phonenumberArray.size()]), addressArray
              .toArray(new String[addressArray.size()])));
      listview.setOnItemClickListener(new OnItemClickListener() {
  
          // xử lý sự kiện khi chọn item trên listview
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                  int position, long id) {
              Intent j = new Intent(mContext, Menu_Main.class);
  
              // lấy thông tin thông qua vị trí của item được chọn
              String url = urlArray.get(position);
              String address = addressArray.get(position);
              String mahoadon = codeInvoiceArray.get(position);
              String phone = phonenumberArray.get(position);
  
              // chuyển thông tin này qua bên phần MENU
              j.putExtra("url", url);
              j.putExtra("address", address);
              j.putExtra("mahoadon", mahoadon);
              j.putExtra("phone", phone);
              j.putExtra("ID", iddelivery);
              mContext.startActivity(j);
          }
      });
  }
  
  }
  </code></pre>
  
  <p>Class main</p>
  
  <pre><code>public class Invoice extends Activity {
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.invoice);
      mDb.openDB();
          Cursor mCursor = mDb.getAllInvoice(IDDelivery);
          if (mCursor.moveToFirst()) {
              do {
  
                  LoadListView load=new LoadListView(Invoice.this, mCursor.getString(1), mCursor.getString(2) ,mCursor.getString(3), mCursor.getString(4), mCursor.getString(5), IDDelivery);
                  load.loaddatalistview();
  
              } while (mCursor.moveToNext());
              //loaddatalistview();
          }
          mDb.closeDB();
  }
  </code></pre>
  
  <p>Error notice</p>
  
  <pre><code>12-25 14:03:38.033: W/System.err(21335): java.lang.NullPointerException
  12-25 14:03:38.041: W/System.err(21335):    at Support.LoadListView.&lt;init&gt;(LoadListView.java:23)
  12-25 14:03:38.041: W/System.err(21335):    at com.longvan.saigonfleamarket.Invoice.workoffline(Invoice.java:226)
  12-25 14:03:38.041: W/System.err(21335):    at com.longvan.saigonfleamarket.Invoice.onCreate(Invoice.java:65)
  12-25 14:03:38.041: W/System.err(21335):    at android.app.Activity.performCreate(Activity.java:4465)
  12-25 14:03:38.041: W/System.err(21335):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
  12-25 14:03:38.041: W/System.err(21335):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
  12-25 14:03:38.041: W/System.err(21335):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
  12-25 14:03:38.041: W/System.err(21335):    at android.app.ActivityThread.access$600(ActivityThread.java:128)
  12-25 14:03:38.041: W/System.err(21335):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
  12-25 14:03:38.041: W/System.err(21335):    at android.os.Handler.dispatchMessage(Handler.java:99)
  12-25 14:03:38.041: W/System.err(21335):    at android.os.Looper.loop(Looper.java:137)
  12-25 14:03:38.041: W/System.err(21335):    at android.app.ActivityThread.main(ActivityThread.java:4514)
  12-25 14:03:38.041: W/System.err(21335):    at java.lang.reflect.Method.invokeNative(Native Method)
  12-25 14:03:38.041: W/System.err(21335):    at java.lang.reflect.Method.invoke(Method.java:511)
  12-25 14:03:38.041: W/System.err(21335):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
  12-25 14:03:38.041: W/System.err(21335):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
  12-25 14:03:38.041: W/System.err(21335):    at dalvik.system.NativeStart.main(Native Method)
  12-25 14:03:38.041: I/System.out(21335): Workoffline!!!
  </code></pre>