Android空指针异常SQLite

Android空指针异常SQLite,android,nullpointerexception,android-sqlite,Android,Nullpointerexception,Android Sqlite,我试图从我的数据库中获取书籍数据,但我一直遇到NullPointerException。我有一个双数组条目,我想用一本书的项目和它的5个相应的细节填充。我知道我在InventoryAdapter数组中有额外的元素,我在这个方法中不使用这些元素,但我将它们保留在那里,因为我在其他地方使用它 错误发生在条目[i][0]=InventoryAdapter.getInventoryByISBN(记录[i][0])[1]并扩展为Cursor Cursor=db.rawQuery(query,新字符串[]{

我试图从我的数据库中获取书籍数据,但我一直遇到NullPointerException。我有一个双数组条目,我想用一本书的项目和它的5个相应的细节填充。我知道我在InventoryAdapter数组中有额外的元素,我在这个方法中不使用这些元素,但我将它们保留在那里,因为我在其他地方使用它

错误发生在
条目[i][0]=InventoryAdapter.getInventoryByISBN(记录[i][0])[1]并扩展为
Cursor Cursor=db.rawQuery(query,新字符串[]{ISBN})

为什么光标处会出现错误?我原以为调用不存在的数组位置时可能会发生错误

主代码

int numEntries = 2;
Entries = new String[numEntries][5];
     int totalCount = 0;
     if (BuildConfig.DEBUG)
            Log.d(debug.LOG, "numEntries="+numEntries);

     Toast.makeText(ReportsByDateScreen.this, "numEntries="+numEntries, Toast.LENGTH_LONG).show();

    // Set up search array
    for(int i = 0; i < numEntries; i++)
    {
        Entries[i][0] = InventoryAdapter.getInventoryByISBN(records[i][0])[1];
        Entries[i][1] = InventoryAdapter.getInventoryByISBN(records[i][0])[2];
        Entries[i][2] = InventoryAdapter.getInventoryByISBN(records[i][0])[4];
        Entries[i][3] = InventoryAdapter.getInventoryByISBN(records[i][0])[3];
        for(int j = 0; j < records.length; j++)
        {
            if(records[j][0].equals(InventoryAdapter.getInventoryByISBN(records[i][0])[0]))
            {
                totalCount+=Integer.parseInt(InventoryAdapter.getInventoryByISBN(records[i][0])[8]);
            }
        }
        Entries[i][4] = ((Integer)totalCount).toString();
        reportArray.add(new ReportsItem(records[i][0],Entries[i]));
        totalCount = 0;
    }
int numEntries=2;
Entries=新字符串[numEntries][5];
int totalCount=0;
if(BuildConfig.DEBUG)
Log.d(debug.Log,“numEntries=“+numEntries”);
Toast.makeText(ReportsByDateScreen.this,“numEntries=“+numEntries,Toast.LENGTH_LONG).show();
//设置搜索数组
for(int i=0;i
目录适配器

public static String[] getInventoryByISBN(String ISBN)
{
    String[] entry = new String[9];
    //Query
    String query = "select * from INVENTORY where ISBN = ?";
    Cursor cursor = db.rawQuery(query, new String[] {ISBN});
    if(cursor.getCount()<1) // title Not Exist
    {
        cursor.close();
        for(int i = 0; i < 9; i++)
            entry[i] = "Not Found";
        return entry;
    }
    cursor.moveToFirst();
    //put data into respective variable
    int publish = cursor.getInt(cursor.getColumnIndex("PUBLISH_DATE"));
    String publishdate = ((Integer)publish).toString();
    String title = cursor.getString(cursor.getColumnIndex("TITLE"));
    String author = cursor.getString(cursor.getColumnIndex("AUTHOR"));
    String callNumber = cursor.getString(cursor.getColumnIndex("CALL_NUMBER"));
    int available = cursor.getInt(cursor.getColumnIndex("AVAILABLE_COUNT"));
    String availablecount = ((Integer)available).toString();
    int inventory = cursor.getInt(cursor.getColumnIndex("INVENTORY_COUNT"));
    String inventorycount = ((Integer)inventory).toString();
    int due = cursor.getInt(cursor.getColumnIndex("DUE_PERIOD"));
    String dueperiod = ((Integer)due).toString();
    int checkoutcount = cursor.getInt(cursor.getColumnIndex("COUNT"));
    String count = ((Integer)checkoutcount).toString();
    //combine variables into one array
    entry[0] = ISBN;
    entry[1] = title;
    entry[2] = author;
    entry[3] = publishdate;
    entry[4] = callNumber;
    entry[5] = availablecount;
    entry[6] = inventorycount;
    entry[7] = dueperiod;
    entry[8] = count;
    cursor.close();
    return entry;
}
公共静态字符串[]getInventoryByISBN(字符串ISBN)
{
字符串[]项=新字符串[9];
//质疑
String query=“从ISBN=?”的库存中选择*;
Cursor Cursor=db.rawQuery(查询,新字符串[]{ISBN});

如果(cursor.getCount(),这里有两种不同的可能性:

  • ISBN为空(扩展记录[i][0]也为空)
  • 数据库为空
如果我是你,我会调查的。 使用调试器

我可以告诉您很多,因为您没有发布
SQLiteDatabase
的init代码