Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何让游标从SQLite数据库读取下一行?_Android_Sqlite_Pdf - Fatal编程技术网

Android 如何让游标从SQLite数据库读取下一行?

Android 如何让游标从SQLite数据库读取下一行?,android,sqlite,pdf,Android,Sqlite,Pdf,我正试图从我的数据库中从某些字段获取一份PDF格式的报告。pdf生成得非常完美,但它只是从数据库中读取第一个条目,而不是所有条目 这是我的PDF代码: public void exportDataBaseIntoPDF() { Document doc = new Document(PageSize.A4); try { path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/M

我正试图从我的数据库中从某些字段获取一份PDF格式的报告。pdf生成得非常完美,但它只是从数据库中读取第一个条目,而不是所有条目

这是我的PDF代码:

public void exportDataBaseIntoPDF() {
    Document doc = new Document(PageSize.A4);
    try {
        path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/MSS Jobsheets";
        date = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).format(new Date());

        File dir = new File(path);
        if (!dir.exists())
            dir.mkdirs();

        Log.d("PDFCreator", "PDF Path: " + path);

        filePDF = new File(dir, "Report" + "(" + date + ")" + ".pdf");
        FileOutputStream fOut = null;
        try {
            fOut = new FileOutputStream(filePDF);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        PdfWriter.getInstance(doc, fOut);
        doc.open();

        DBHelper db = new DBHelper(this);
        Cursor cursor = db.getDataItem();
        int count = cursor.getCount();

        cursor.moveToFirst();

        for (int j = 0; j < count; j++) {
            PdfPTable table = new PdfPTable(2);
            table.addCell(cursor.getString(cursor.getColumnIndex("name")));
            table.addCell(cursor.getString(cursor.getColumnIndex("gender")));


            cursor.moveToNext();

            doc.add(table);
            doc.close();
        }

    } catch (DocumentException e) {
        e.printStackTrace();
    }
}
但正如我所说,它只从数据库中读取第一行并添加数据,而不移动到数据库中的下一行以将数据添加到PDF中

有人能帮我解决这个问题吗?
提前谢谢

实际问题与游标无关,游标读取下一行,但在第一次数据写入后关闭文档。尝试关闭for循环外部的文档对象

将该行置于循环的
外部

 doc.close();

数据库中有多行吗?有。基本上,这是用户填写的表单,然后在一天结束时,用户可以从某些字段中提取报告,然后发送电子邮件。尝试关闭doc out side for loop。写此行doc.close();外面谢谢!现在开始工作了。真不敢相信我竟然错过了!我为此奋斗了很久@菜鸟很乐意帮助你。。!
 doc.close();