Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.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 我在slqite数据库中输入了数据。getCount()为null,错误为:-无效表_Android_Sqlite_Android Sqlite_Sqliteopenhelper - Fatal编程技术网

Android 我在slqite数据库中输入了数据。getCount()为null,错误为:-无效表

Android 我在slqite数据库中输入了数据。getCount()为null,错误为:-无效表,android,sqlite,android-sqlite,sqliteopenhelper,Android,Sqlite,Android Sqlite,Sqliteopenhelper,这是我的代码,通过该代码我将数据输入数据库,并接收到currentrowId,在该代码上输入数据,currentrow_id正在更新,但cursor.getcount仍然为空 SQLiteDatabase dbr = help.getReadableDatabase(); String[] projection = { columnid, columnimage, columnttitle, columndesripti

这是我的代码,通过该代码我将数据输入数据库,并接收到currentrowId,在该代码上输入数据,currentrow_id正在更新,但cursor.getcount仍然为空

     SQLiteDatabase dbr = help.getReadableDatabase();

String[] projection = {
        columnid,
        columnimage,
        columnttitle,
        columndesription,
        columnurl
};
Cursor cursor = dbr.query(tablename, projection, null, null, null, null, null);
Cursor cur = dbr.query(tablename, projection, null, null, null, null, null);  
    for (int i = 0; i < mModelList1.size(); i++) {
cursor.moveToFirst();
        if (cursor.getCount()==0){
            Insert_in_a_row(i,1,mModelList1,help);
            cur.moveToLast();
            Log.d("uniq cursor.getCount()=",""+cursor.getCount()); //here i get the cursor.getcount()  null
        }

        Log.d("fist cursor.getCount()=",""+cursor.getCount());
        while (!cursor.isAfterLast()) {

            if(cursor.getCount()>0) {
                cur.moveToLast();
                int Id = cur.getInt(cur.getColumnIndex(columnid)) + 1;
                Log.d("size of mModellist ", "" + mModelList1.size());
                Insert_in_a_row(i, Id, mModelList1, help);
                Log.d("scnd cursor.getCount()=", "" + cur.getCount()); //here i get the cursor.getcount()  null

            }
    cursor.moveToLast();
            cursor.moveToNext();
        }if(i==mModelList1.size()-1){cursor.close();
            cur.close();
            dbr.close();}

    }
MainActivity日志消息如下所示

  W/System.err: java.lang.IllegalStateException: Invalid tables
 W/System.err:     at android.database.sqlite.SQLiteDatabase.findEditTable(SQLiteDatabase.java:973)
W/System.err:     at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1163)
W/System.err:     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1034)
W/System.err:     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1202)  
W/System.err:     at com.Newsforest.android.Newsforest.MainActivity.gatherInformation(MainActivity.java:346)
W/System.err:     at com.Newsforest.android.Newsforest.MainActivity.onCreate(MainActivity.java:179)
W/System.err:     at android.app.Activity.performCreate(Activity.java:5990)
W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
W/System.err:     at android.app.ActivityThread.access$800(ActivityThread.java:151)
W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err:     at android.os.Looper.loop(Looper.java:135)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5254)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
下面是我收到错误的MainActivity代码

      try {//News_dbhelper mdbHelper= new News_dbhelper(this);
      SQLiteDatabase db = mdbHelper.getReadableDatabase();

     SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
      queryBuilder.setTables(tablename);
      String[] projection = {
              columnid,
              columnimage,
              columnttitle,
              columndesription,
              columnurl
      };
      Cursor C= db.query(tablename,
              projection,
              null,
              null,
              null,
              null,
              null);

     // Log.d( "gatherInformation: ",""+C.getCount());

      C.moveToFirst();
      while (C.isAfterLast()){
          NewsModel model = new NewsModel();
          //Cursor cursor1 = db.rawQuery(" SELECT * FROM " + tablename + " WHERE " + columnid + "=?", new String[]{String.valueOf(j)});
          model.setTitle(C.getString(C.getColumnIndex(columnttitle)));
          model.setDescription(C.getString(C.getColumnIndex(columndesription)));
          model.setUrl(C.getString(C.getColumnIndex(columnurl)));
          model.setimage(C.getString(C.getColumnIndex(columnimage)));
          mModelList.add(model);
          C.moveToNext();
      }
      C.close();
  }catch (SQLiteException e){e.printStackTrace();
   Toast.makeText(this,"error reason"+e.toString(),Toast.LENGTH_LONG).show();}
   catch (Exception e){e.printStackTrace();}
   finally {
      Log.d("size of mModellist ",""+mModelList.size());
      recyclerView.setAdapter(new Adapter(MainActivity.this,mModelList));

  }
不过,显示的是黑屏,而不是recyclerView

W/CursorWindow: Window is full: requested allocation 892521 bytes, free space 572848 bytes, window size 2097152 bytes
W/CursorWindow: Window is full: requested allocation 617180 bytes, free space 565848 bytes, window size 2097152 bytes
W/CursorWindow: Window is full: requested allocation 675170 bytes, free space 91920 bytes, window size 2097152 bytes
D/size of mModellist: 8
W/ResourcesManager: Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
W/ResourcesManager: Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
D/DynamitePackage: Instantiated singleton DynamitePackage.
D/DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl

光标允许您访问查询结果集。如果在查询后插入新数据,则查询结果集不会更改。因此,光标计数保持在0

您需要再次查询数据库以查看新数据


在System.err日志中被视为警告的NPE不是由您发布的代码版本生成的。

post errorslog@ALTegani我更新了错误日志,看看这个@ALTegani谢谢,但这不是我想要的答案。请查看MainActivity错误日志和获取错误的MainActivity代码。我已经更新了这个问题。@bharatsingh关于SO的问题是关于一个特定的编程问题。问题不在于提供正在进行的调试服务。你应该问一个新问题。另外,您的问题很可能是由于在DB中存储大型图像,而您应该在DB中存储路径并从文件中检索图像本身。在这方面有很多答案,所以搜索就足够了。我在mainActivity中有另一个查询,返回同一数据库的空光标。请查看我更新的mainActivity错误日志,以及我收到错误的mainActivity代码。谢谢。错误已被删除,谢谢@laalto您为我做了很多,但仍然,它显示一个黑屏。
      try {//News_dbhelper mdbHelper= new News_dbhelper(this);
      SQLiteDatabase db = mdbHelper.getReadableDatabase();

     SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
      queryBuilder.setTables(tablename);
      String[] projection = {
              columnid,
              columnimage,
              columnttitle,
              columndesription,
              columnurl
      };
      Cursor C= db.query(tablename,
              projection,
              null,
              null,
              null,
              null,
              null);

     // Log.d( "gatherInformation: ",""+C.getCount());

      C.moveToFirst();
      while (C.isAfterLast()){
          NewsModel model = new NewsModel();
          //Cursor cursor1 = db.rawQuery(" SELECT * FROM " + tablename + " WHERE " + columnid + "=?", new String[]{String.valueOf(j)});
          model.setTitle(C.getString(C.getColumnIndex(columnttitle)));
          model.setDescription(C.getString(C.getColumnIndex(columndesription)));
          model.setUrl(C.getString(C.getColumnIndex(columnurl)));
          model.setimage(C.getString(C.getColumnIndex(columnimage)));
          mModelList.add(model);
          C.moveToNext();
      }
      C.close();
  }catch (SQLiteException e){e.printStackTrace();
   Toast.makeText(this,"error reason"+e.toString(),Toast.LENGTH_LONG).show();}
   catch (Exception e){e.printStackTrace();}
   finally {
      Log.d("size of mModellist ",""+mModelList.size());
      recyclerView.setAdapter(new Adapter(MainActivity.this,mModelList));

  }
W/CursorWindow: Window is full: requested allocation 892521 bytes, free space 572848 bytes, window size 2097152 bytes
W/CursorWindow: Window is full: requested allocation 617180 bytes, free space 565848 bytes, window size 2097152 bytes
W/CursorWindow: Window is full: requested allocation 675170 bytes, free space 91920 bytes, window size 2097152 bytes
D/size of mModellist: 8
W/ResourcesManager: Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
W/ResourcesManager: Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
D/DynamitePackage: Instantiated singleton DynamitePackage.
D/DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl