swing - JTable: Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0 -


i have problem when called function. created jtable , want show data arraylist. please, me solve it!

 private void loaddata()   {         string[] columns = new string [] { "ho", "tenlot", "ten", "ma", "ngsinh", "dia chi", "phai","luong", "manvql", "phong" };          defaulttablemodel model = new defaulttablemodel(null , columns);         arraylist<clsnhanvien> ds = new arraylist<clsnhanvien>();         ds = nhanviendao.nhanviendao.laydanhsachnhanvien();          (int = 0; <ds.size(); i++)         {             string ho = ds.get(i).gethonv();             string tenlot = ds.get(i).gettenlot();             string ten = ds.get(i).gettennv();             string ma = ds.get(i).getmanv();             date ns = ds.get(i).getngaysinh();             string dchi = ds.get(i).getdiachi();             string phai = ds.get(i).getphai();             float luong = ds.get(i).getluong();             string manvql = ds.get(i).getma_nql();             int phg = ds.get(i).getphong();              object[] items = new object[] {ho, tenlot, ten, ma, ns, dchi, phai, luong, manvql, phg};                 model.addrow(items);         }           jtable1.setrowheight(30);         jtable1.getcolumnmodel().getcolumn(0).setpreferredwidth(70);         jtable1.getcolumnmodel().getcolumn(1).setpreferredwidth(70);         jtable1.getcolumnmodel().getcolumn(2).setpreferredwidth(70);         jtable1.getcolumnmodel().getcolumn(3).setpreferredwidth(70);         jtable1.getcolumnmodel().getcolumn(4).setpreferredwidth(200);         jtable1.getcolumnmodel().getcolumn(5).setpreferredwidth(200);         jtable1.getcolumnmodel().getcolumn(6).setpreferredwidth(70);         jtable1.getcolumnmodel().getcolumn(7).setpreferredwidth(70);         jtable1.getcolumnmodel().getcolumn(8).setpreferredwidth(70);         jtable1.getcolumnmodel().getcolumn(9).setpreferredwidth(70);     } 

it seems have empty arraylist... try adding object manually in array , in model... , refactor way

for (clsnhanvien element : ds) {      string ho = element.gethonv();     string tenlot = element.gettenlot();     string ten = element.gettennv();     string ma = element.getmanv();     date ns = element.getngaysinh();     string dchi = element.getdiachi();     string phai = element.getphai();     float luong = element.getluong();     string manvql = element.getma_nql();     int phg = element.getphong();      object[] items = new object[] {ho, tenlot, ten, ma, ns, dchi, phai, luong, manvql, phg};         model.addrow(items); } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -