mysql - Java - String NullPointerException -


i'm making mysql database connector java show data. when run code, nullpointerexception in getdata() function. here code.

public string[][] getdata() { string values[][]; try {     rs = st.executequery("select * adresses");     int = 0;     while(rs.next()) {     string id = rs.getstring("id");      string name = rs.getstring("name");      string adress = rs.getstring("email_adress");      string catagory = rs.getstring("catarogy");      values[i][0] = id;     values[i][1] = name;     values[i][2] = adress;     values[i][3] = catagory;     i++;     }     return values; } catch (sqlexception e) {     e.printstacktrace();     return values; } } 

when value of string values nothing error. if give string allready value says nothing .

public string[][] getdata() { string values[][] = {{"","","",""},          {"","","",""},          {"","","",""},}; try {     rs = st.executequery("select * adresses");     int = 0;     while(rs.next()) {     string id = rs.getstring("id");      string name = rs.getstring("name");      string adress = rs.getstring("email_adress");      string catagory = rs.getstring("catarogy");      values[i][0] = id;     values[i][1] = name;     values[i][2] = adress;     values[i][3] = catagory;     i++;     }     return values; } catch (sqlexception e) {     e.printstacktrace();     return values; } } 

i want more data in data string. how can let automatically that?? tnx.

ps. function called in class framegui , has change object

public class framegui extends jframe {

public jtable dataholder; mysql mysql = new mysql();  public string[] columnnames = {     "id", "name", "adress", "catagory" };  -> public object[][] data = mysql.getdata();  public framegui() { init(); mysql.getdata(); } 

}

you not initialize string values[][] null. either need initialize first or use more appropriate datastructure list.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -