【发布时间】:2014-06-27 18:01:31
【问题描述】:
我有问题。如何将数据从 SQL 数据库放入 Number 数组。我想把它们放在一个图表中
我有一个NullPointerException 用于这些命令
Number[] series2Numbers={s1nInt[1]};
这是我的完整代码
openDB();
Cursor c = myDb.getSpalte();
while (c.moveToPrevious())
{
s1nInt[i] = c.getInt(1);
i++;
c.moveToPrevious();
}
c.close();
closeDB();
Number[] series2Numbers={s1nInt[1]};
这是我的例外:
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
我的 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;
}
我需要这个数组:
XYSeries series1 = new SimpleXYSeries(
Arrays.asList(series1Numbers), // SimpleXYSeries takes a List so turn our array into a List
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Y_VALS_ONLY means use the element index as the x value
"Series1"); // Set the display title of the series
【问题讨论】:
-
向我们展示您的数据库查询(
getSpalte())。我猜 myDb 是你自己的类型,因为它有一个名为“getSpalte()”的方法。并且请包括查询表的结构。 -
乍一看,
s1nInt数组的大小似乎小于2。 -
@Michael:乍一看,您会发现这会产生
ArrayIndexOutOfBoundsException而不是NPE。但是,看起来结果只有 1 列。 -
@fabian 你是对的..对不起..
标签: java android sql arrays eclipse