标签: android-cursor

在SQLiteDatabase.query()中使用String [] selectionArgs

如何使用String[] selectionArgsSQLiteDatabase.query()?我希望我可以把它设置为null,因为我没有用它.我只是尝试将数据库中的整个未排序表加载到Cursor.有关如何实现这一目标的任何建议?

android android-cursor android-sqlite

49
推荐指数
2
解决办法
4万
查看次数

android java.lang.IllegalStateException:无法从CursorWindow读取第0行,第0列

我正在开发一个应用程序,它下载一些文件并将它们的文本保存在file_content字段中.文件大小可能从几KB到10 MB不等.该应用程序适用于所有尺寸,同时保存.在long file_content记录上使用select语句时会发生此问题.它给

java.lang.IllegalStateException:无法从CursorWindow读取第0行col 0

何时获取此类行.字段内容大小有限制吗?如果是这样,那么为什么它让我们在检索时保存并给出错误?这是我的代码剪切,提取行:

public String getFileContent(MyFile gc) {
        if(!isDBOpen()) {
            open();
        }
        try {
            String mQuery = "SELECT * FROM " + DBOpenHelper.TABLE_SAVED_FILES + " WHERE " + DBOpenHelper.COLUMN_ID + " = " + gc.id;
            Cursor mCursor = database.rawQuery(mQuery, null);
            if(mCursor.getCount() <= 0) {
                return null;
            }
            if(mCursor.moveToFirst()) {
                return getCursorRowContent(mCursor);
            }
        } catch (Exception e) {
            e.getMessage();
        }
        return null;
    }

    private String getCursorRowContent(Cursor mCursor) throws Exception {
        return mCursor.getString(mCursor.getColumnIndex(DBOpenHelper.COLUMN_FILE_CONTENT));
    }
Run Code Online (Sandbox Code Playgroud)

知道发生了什么事吗?我已经在2到3台设备上进行了测试.

Logcat输出:

01-29 13:41:56.520: W/CursorWindow(4121): …
Run Code Online (Sandbox Code Playgroud)

sqlite android android-cursor

40
推荐指数
1
解决办法
3万
查看次数

是否可以让Android应用程序中的所有活动共享一个SQLiteOpenHelper实例?

将单个SQLiteOpenHelper实例作为子类应用程序的成员,并且所有需要SQLiteDatabase实例的活动从一个帮助程序获取它是否可以?

java sqlite android android-cursor android-loadermanager

39
推荐指数
4
解决办法
2万
查看次数

Android Studio - 值必须是?0

我在 Android Studio 中收到与光标有关的错误。

\n

我的代码中有以下行

\n
String data = cursor.getString(cursor.getColumnIndex(columnIndex));\n
Run Code Online (Sandbox Code Playgroud)\n

columnIndex 被传递到该方法中。

\n

这部分cursor.getColumnIndex(columnIndex)产生以下错误

\n

值必须是 \xe2\x89\xa5 0

\n

当它也使用游标时,它发生在我的 DBHelper 类和我的回收器适配器中。

\n

它显示为红色错误,但应用程序仍然可以正常构建和运行。

\n

有任何想法吗?

\n

谢谢你的帮助。

\n

21 年 9 月 22 日更新

\n

我根据要求添加了一些代码以及我如何解决此错误。但不确定这是否是最好的方法。

\n

所以我使用的方法是这样的......

\n
public String getTripInfo(String tableName, int tripNo, String columnIndex){\n    String data = "";\n\n    // Select all query\n    String selectQuery = "SELECT * FROM " + tableName + " WHERE " + TRIP_DETAILS_TRIP_NUMBER + "=" + tripNo;\n\n    SQLiteDatabase db = …
Run Code Online (Sandbox Code Playgroud)

android android-cursor

37
推荐指数
2
解决办法
2万
查看次数

如何在Android中使用光标数据创建列表数组

如何使用光标数据创建列表数组(滚动时列表显示第一个字母)?

android arraylist android-cursor android-sqlite

35
推荐指数
3
解决办法
6万
查看次数

如何在EditText中禁用光标定位和文本选择?(机器人)

我正在寻找一种方法来阻止用户将光标位置移动到任何地方.光标应始终保持在当前EditText值的末尾.除此之外,用户不应该在EditText中选择任何内容.您是否知道如何在Android中使用EditText实现这一目标?

澄清一下:用户应该能够插入文本,但仅限于最后.

android textselection android-edittext android-cursor

30
推荐指数
3
解决办法
2万
查看次数

Android RecyclerView + CursorLoader + ContentProvider +"加载更多"

我创建了一个Activity,因为我正在实现CursorLoader以从数据库加载数据.

我已经为该表的所有记录做了那件事,但我想加载30-30条记录,比如加载更多功能

我试图创建查询并加载前30条记录,但我无法理解如何请求新记录.

我的活动代码如下:

public class ProductListActivity extends AppCompatActivity
        implements LoaderManager.LoaderCallbacks<Cursor> {

    /**
     * Records in list
     */
    int offset = 0;

    /**
     * For Current Activity *
     */
    Context mContext;

    /**
     * Activity Binding
     */
    ActivityProductListBinding activityProductListBinding;

    /**
     * Product Adapter
     */
    ProductListAdapter productListAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        /**
         * DataBinding with XML
         */
        activityProductListBinding = DataBindingUtil.setContentView(this, R.layout.activity_product_list);

        /**
         * Getting Context
         */
        mContext = getApplicationContext();

        /***
         * TOOLBAR Settings...
         */
        setSupportActionBar(activityProductListBinding.toolbar);
        activityProductListBinding.toolbarTitleTextview.setText(R.string.string_title_products); …
Run Code Online (Sandbox Code Playgroud)

android android-contentprovider android-cursor android-cursorloader android-cursoradapter

30
推荐指数
1
解决办法
1万
查看次数

API Level <11的Cursor.getType()

我正在查询CallLog内容提供程序,需要检测列类型.

在Honeycomb和更新版本(API Level 11+)中,您可以通过调用Cursor.getType(int columnIndex)返回以下类型之一的方法获取列首选数据类型:

  • FIELD_TYPE_NULL(0)
  • FIELD_TYPE_INTEGER(1)
  • FIELD_TYPE_FLOAT(2)
  • FIELD_TYPE_STRING(3)
  • FIELD_TYPE_BLOB(4)

如何在Honeycomb <11设备上实现这一目标?

我尝试过以下方法:

for ( int i = 0; i < cursor.getColumnCount(); i++ ) {    

    int columnType = -1;
    try {
        cursor.getInt( i );
        columnType = Cursor.FIELD_TYPE_INTEGER;

    } catch ( Exception ignore ) {

        try {
            cursor.getString( i );
            columnType = Cursor.FIELD_TYPE_STRING;

        } catch ( Exception ignore1 ) {

            try {
                cursor.getFloat( i );
                columnType = Cursor.FIELD_TYPE_FLOAT;

            } catch ( Exception ignore2 ) {

                try {                                             
                  cursor.getBlob( i …
Run Code Online (Sandbox Code Playgroud)

android android-contentprovider android-cursor

24
推荐指数
2
解决办法
7874
查看次数

如何更新现有联系人?

我有一个现有联系人,我需要为现有联系人添加工作地址.我使用以下代码,但它不起作用.

String selectPhone = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='" + 
    ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE + 
    "'" + " AND " + ContactsContract.CommonDataKinds.StructuredPostal.TYPE + "=?"; 
String[] phoneArgs = new String[]
    {String.valueOf(ContactId), String.valueOf(
    ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK)}; 
ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI) 
    .withSelection(selectPhone, phoneArgs) 
    .withValue(ContactsContract.CommonDataKinds.StructuredPostal.STREET, STREET)
    .withValue(ContactsContract.CommonDataKinds.StructuredPostal.CITY, CITY) 
    .withValue(ContactsContract.CommonDataKinds.StructuredPostal.REGION, REGION)
    .withValue(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE, POSTCODE) 
    .withValue(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY, COUNTRY)  
    .build()); 
this.context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 
Run Code Online (Sandbox Code Playgroud)

对此有何解决方案?

android contacts android-contacts android-cursor

20
推荐指数
2
解决办法
1万
查看次数

无法从活页夹创建光标窗口

1 Cursor cursor = contentResolver.query(MY_URI, new String[] { "first" }, null, null, null);
2 if (cursor != null) {
3   if (cursor.moveToFirst()) {
4       first = cursor.getString(cursor.getColumnIndex("first"));
5       cursor.close();
6   }
7 }
Run Code Online (Sandbox Code Playgroud)

然后在第3行(根据日志),我偶尔会遇到这个例外(摘录如下):

android.database.CursorWindowAllocationException: Cursor window could not be created from binder.
    at android.database.CursorWindow.<init>(CursorWindow.java:134)
    at android.database.CursorWindow.<init>(CursorWindow.java:41)
    at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:709)
    at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:707)
    at android.database.CursorWindow.newFromParcel(CursorWindow.java:718)
    at android.database.BulkCursorProxy.getWindow(BulkCursorNative.java:196)
Run Code Online (Sandbox Code Playgroud)

...

任何想法为什么抛出这个例外?谢谢!

android cursor android-cursor

20
推荐指数
2
解决办法
1万
查看次数