Android - Cursor循环跳过第一行

时间:2015-11-05 23:59:16

标签: android

这段代码的作用是每个"项目"这些保存在SQLite数据库中并在线上传到Parse.com

请帮助我理解为什么此代码不会上传第一个条目。我相信我的订单会以某种方式混淆。它似乎只从Cursor的第2行开始。

Cursor c = dbHelper.fetchAllProjects();
    String[] data;
    c.moveToFirst();
    if (c != null) {
        while (c.moveToNext()) {

            Toast.makeText(getApplicationContext(), "Message : " + c.getCount(), Toast.LENGTH_LONG).show();

            String s = c.getString(5);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date d = new Date();
            try {
                d = dateFormat.parse(s);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            data = new String[8];
            data[0] = c.getString(0);
            data[1] = c.getString(1);
            data[2] = c.getString(2);
            data[3] = c.getString(3);
            data[4] = c.getString(4);
            data[6] = c.getString(6);
            data[7] = c.getString(7);

            Project p1 = new Project(Integer.valueOf(data[0]), data[1], data[2], data[3], data[4], d, data[6], data[7]);

            ParseObject p2 = new ParseObject("Project");
            p2.put("projectSubject", p1.getProjectSubject());
            p2.put("projectType", p1.getProjectType());
            p2.put("projectTitle", p1.getProjectTitle());
            p2.put("projectWorth", p1.getProjectWorth());
            p2.put("projectDueDate", p1.getProjectDueDate());
            p2.put("projectDetails", p1.getProjectDetails());
            p2.put("email", "chrismaher.wit@gmail.com");

            ///////////////////////////////////

            ParseQuery<ParseObject> querySubject = ParseQuery.getQuery("Project");
            querySubject.whereEqualTo("projectSubject", p1.getProjectSubject());

            ParseQuery<ParseObject> queryTitle = ParseQuery.getQuery("Project");
            queryTitle.whereEqualTo("projectTitle", p1.getProjectTitle());

            ParseQuery<ParseObject> queryDetails = ParseQuery.getQuery("Project");
            queryDetails.whereEqualTo("projectDetails", p1.getProjectDetails());

            List<ParseQuery<ParseObject>> queries = new ArrayList<ParseQuery<ParseObject>>();
            queries.add(querySubject);
            queries.add(queryTitle);
            queries.add(queryDetails);

            ParseQuery<ParseObject> mainQuery = ParseQuery.or(queries);
            mainQuery.findInBackground(new FindCallback<ParseObject>() {
                @Override
                public void done(List<ParseObject> list, com.parse.ParseException e) {

                    listSize = list.size();
                    Toast.makeText(getApplicationContext(), "ListSize : " + listSize, Toast.LENGTH_LONG).show();

                }
            });

            if (listSize == 0) {

                p2.saveInBackground();

            }


        }
        c.close();
    }

1 个答案:

答案 0 :(得分:1)

<input>

那是你的问题