java - Put Sql Data to a Number Array -


i have problem. how can put data sql database number array. put them in graph

i got nullpointerexception these command

number[] series2numbers={s1nint[1]}; 

here full code

opendb(); cursor c = mydb.getspalte();          while (c.movetoprevious()) {             s1nint[i] = c.getint(1);     i++;     c.movetoprevious();  } c.close(); closedb();      number[] series2numbers={s1nint[1]}; 

and here exception:

graph.onstart() line: 85     graph(fragment).performstart() line: 1801    fragmentmanagerimpl.movetostate(fragment, int, int, int, boolean) line: 937   fragmentmanagerimpl.movetostate(int, int, int, boolean) line: 1106   backstackrecord.run() line: 690      fragmentmanagerimpl.execpendingactions() line: 1571     fragmentmanagerimpl$1.run() line: 447    handler.handlecallback(message) line: 733    handler.dispatchmessage(message) line: 95    

my getspalte()

public cursor getspalte(){     string where= null;     string order = "_id desc";     cursor c =  db.query(true, database_table, key_kaloa,              where, null, null, null, order, null);   if (c != null) {   c.movetofirst(); }   return c; } 

i need array this:

 xyseries series1 = new simplexyseries(                      arrays.aslist(series1numbers),          // simplexyseries takes list turn our array list                      simplexyseries.arrayformat.y_vals_only, // y_vals_only means use element index x value                      "series1");                             // set display title of series 

s1nint null in line

number[] series2numbers={s1nint[1]}; 

maybe never initialize s1nint or set null somewhere. part of line produce nullpointerexception.

also implies c.movetoprevious() failed.

from api doc of cursor.movetoprevious():

this method return false if cursor before first entry in result set.

maybe have change movetoprevious() movetonext() too. (the cursor @ position before first entry directly after query).

also move cursor twice in each loop iteration. way you'll either odd or rows.


update

after latest edits question seems need list<? extends number> , not array. since elements of list integers, should use arraylist<integer>. way reduce danger of null elements , list. code this:

public cursor getspalte(){     string where= null;     string order = "_id desc";     cursor c =  db.query(true, database_table, key_kaloa, // hope key_kaloa guarantied correct here             where, null, null, null, order, null);     return c; } 


opendb(); cursor c = mydb.getspalte(); list<integer> valuelist = new arraylist<integer>(c.getcount());  while (c.movetonext()) {             valuelist.add(c.getint(0)); // assuming first column of type int } c.close(); closedb();  xyseries series1 = new simplexyseries(                  valuelist,                  simplexyseries.arrayformat.y_vals_only,                  "series1"); 

there several alternatives using arraylist directly, depending on need:

  • if fear list modified, can create list doesn't support modification using collections.unmodifiablelist(list).
  • if indeed need 1 element in list, can use cursor.movetoposition(int) , collections.singletonlist(integer)

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -