问答详情
源自:2-1 数据库的创建好方法的封装

有没有同学用Android Studio 3.0 做的?运行之后老是闪退,怎么解决?

有没有同学用Android Studio 3.0 做的?运行之后老是闪退,怎么解决?

提问者:守护窗明守护爱 2017-12-06 17:24

个回答

  • qq_慕圣9189152
    2021-01-02 18:17:52

    厉害啦

  • 慕仔3825646
    2017-12-25 19:05:24

    你是真的牛逼

  • 守护窗明守护爱
    2017-12-06 17:50:49

    解决了。

    有两个地方需要改。

    1.  public Cursor getAllCostData() {
         SQLiteDatabase database = getWritableDatabase();
         return database.query("imooc_daily", null, null, null, null, null, "cost_date" +"ASC");
      }最后面的排序需要改成 "cost_date ASC"

    2. if (cursor != null) {
         while (cursor.moveToNext()) {
             CostBean costBean = new CostBean();
             costBean.costTitle = cursor.getString(cursor.getColumnIndex("cost_title"));
             costBean.costDate = cursor.getString(cursor.getColumnIndex("cost_date"));
             costBean.costMoney = cursor.getString(cursor.getColumnIndex("cost_money"));
             mCostBeanList.add(costBean);
         }
         cursor.close();
      }这里获取不了cost_money的准确列数,所以需要改成如下形式。

            if (cursor != null) {
       while (cursor.moveToNext()) {
           CostBean costBean = new CostBean();
           int dataColumnIndex = cursor.getColumnIndex("cost_title");
           costBean.costTitle = cursor.getString(dataColumnIndex + 0);
           costBean.costDate = cursor.getString(dataColumnIndex + 1);
           costBean.costMoney = cursor.getString(dataColumnIndex + 2);
           mCostBeanList.add(costBean);
       }
       cursor.close();
    }这里是以cost_title为基准列数,向后退出cost_date和cost_money的列数。