Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.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:无法在数据库中插入Arraylist值_Android_Database_Arraylist_Android Asynctask - Fatal编程技术网

Android:无法在数据库中插入Arraylist值

Android:无法在数据库中插入Arraylist值,android,database,arraylist,android-asynctask,Android,Database,Arraylist,Android Asynctask,我解析了一个json字符串并将值存储在arraylist中,现在我想将这些值放入数据库中,我正在执行异步任务onbackground方法,如下所示: ArrayList<HashMap<String, String>> budget_val = new ArrayList<HashMap<String, String>>(); HashMap<String, String> budget_Val_map = new HashMap&l

我解析了一个json字符串并将值存储在arraylist中,现在我想将这些值放入数据库中,我正在执行异步任务onbackground方法,如下所示:

ArrayList<HashMap<String, String>> budget_val = new ArrayList<HashMap<String, String>>();
 HashMap<String, String> budget_Val_map = new HashMap<String, String>();

     budget_Val_map.put(PRODUCT_CAKE, cake);
     budget_Val_map.put(PRODUCT_YEASTEXTRACT, yeastextract);
     budget_Val_map.put(PRODUCT_BIFLAVOURS, biflavours);
     budget_Val_map.put(PRODUCT_YEASTNUTRIFERM, yeastnutriferm);
budget_val.add(budget_Val_map);

   dbHelper.open();
   dbHelper.topinchartsRecord(new ProductCategory(budget_val));
public void topinchartsRecord(ProductCategory productCategory) {
    try{
        insertRecords(productCategory.getBudget_val(), SQLITE_TABLE3);
        }catch (Exception e) {
                    String LOG_TAG = "mylog";
        Log.e(LOG_TAG, "error reporting", e);
        }}

private void insertRecords(ArrayList<HashMap<String, String>> budget_val,
        String sqliteTable3) {

     if (budget_val != null && budget_val.size() > 0) {

        ContentValues con = new ContentValues();
        for (int i = 0; i < budget_val.size(); i++) {
            con.clear();
            HashMap<String, String> row = budget_val.get(i);
            Iterator<String> it = row.keySet().iterator();

            while (it.hasNext()) {

                String columnName = it.next();
                con.put(columnName, row.get(columnName));
            }

            mDb.insert(SQLITE_TABLE3, null, con);
 Log.d(LOG_TAG, "error reporting");
        System.out.println("Control entered last line of  the insert record=========== 3");
        }}}
ArrayList budget\u val=new ArrayList();
HashMap budget_Val_map=新HashMap();
预算图(产品、蛋糕、蛋糕);
预算价值图投入(产品年度提取,年度提取);
预算-价值-地图-投入(产品-双倍,双倍);
预算-价值-地图投入(产品-YEASTNUTRIFERM,YEASTNUTRIFERM);
预算值添加(预算值映射);
dbHelper.open();
dbHelper.topinchartsRecord(新产品类别(预算值));
现在,在我的数据库适配器中,我创建了一个表,并插入这些值,如下所示:

ArrayList<HashMap<String, String>> budget_val = new ArrayList<HashMap<String, String>>();
 HashMap<String, String> budget_Val_map = new HashMap<String, String>();

     budget_Val_map.put(PRODUCT_CAKE, cake);
     budget_Val_map.put(PRODUCT_YEASTEXTRACT, yeastextract);
     budget_Val_map.put(PRODUCT_BIFLAVOURS, biflavours);
     budget_Val_map.put(PRODUCT_YEASTNUTRIFERM, yeastnutriferm);
budget_val.add(budget_Val_map);

   dbHelper.open();
   dbHelper.topinchartsRecord(new ProductCategory(budget_val));
public void topinchartsRecord(ProductCategory productCategory) {
    try{
        insertRecords(productCategory.getBudget_val(), SQLITE_TABLE3);
        }catch (Exception e) {
                    String LOG_TAG = "mylog";
        Log.e(LOG_TAG, "error reporting", e);
        }}

private void insertRecords(ArrayList<HashMap<String, String>> budget_val,
        String sqliteTable3) {

     if (budget_val != null && budget_val.size() > 0) {

        ContentValues con = new ContentValues();
        for (int i = 0; i < budget_val.size(); i++) {
            con.clear();
            HashMap<String, String> row = budget_val.get(i);
            Iterator<String> it = row.keySet().iterator();

            while (it.hasNext()) {

                String columnName = it.next();
                con.put(columnName, row.get(columnName));
            }

            mDb.insert(SQLITE_TABLE3, null, con);
 Log.d(LOG_TAG, "error reporting");
        System.out.println("Control entered last line of  the insert record=========== 3");
        }}}
public void topinchartsRecord(ProductCategory ProductCategory){
试一试{
插入记录(productCategory.getBudget_val(),SQLITE_TABLE3);
}捕获(例外e){
字符串LOG_TAG=“mylog”;
Log.e(Log_标签,“错误报告”,e);
}}
私有void insertRecords(ArrayList预算值,
字符串(表3){
如果(预算值!=null&&budget\u val.size()>0){
ContentValues con=新的ContentValues();
对于(int i=0;i

但是我的数据库没有显示任何内容,跟踪中没有错误:请让我知道我是否做对了?

没有错误,因为catch块中没有日志。您的catch块为空。你能在那里记录一些东西,看看是否有错误吗?@njzk2它正在进入insertRecords()块..不管怎样,我正在用logi检查,log in catch块现在更新了。。但是没有显示任何内容,因此也不会记录mDb.insert调用的返回值