English 中文(简体)
简称:
原标题:Android: column _id does not exist

我正在发现这一错误。

IllegalArgumentException: column _id does not exist

在使用<代码>SimpleCursorAdapter从我的数据库检索时,表格确实有<代码>_id栏。 谈到这一共同问题,我努力围绕它开展工作,提供了一些在线解决办法,但没有一项工作。 这是我的 cur问:

SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.quoterow, myCursor, new String[]{"_id", "quote"}, new int[]{R.id.quote});

...... 我应提及原件不包括<代码>_id。 我在一栏中补充说,最近尝试并解决这一问题。 是否有任何想法可能有助于解决问题?

最佳回答

你的数据库不需要一个称为“援助”的栏目,但简单CursorAdaptor确实需要返回。 你们可以这样做。

例如,我有一栏表格......

uid,name,number

为简单CursorAdapter查询,我用一个数据库查询:<代码>Qurawery/code>。

SELECT uid as _id,name,number FROM MY_TABLE

该公司进行罚款,并向简单的CursorAdapter提供所需的_id栏。

http://www.un.org。 根据我的理解,“id”领域是一种独特的关键,可以确保 cur子处理的数据能够由适应器和适应性格来正确处理。

Look at the data model in the docs for Content Providers.

无论何种类型的数据库都使用独特的钥匙,这在很大程度上是普遍的做法,而且就我所知,使用一栏名称(或_ID)只是使数据库、内容提供者、治疗者、适应者等各方面的工作标准化和简化的一种方式。

简言之,为了使这些组成部分能够正确开展工作,它们需要一个具有独特价值的数据栏,但它们也必须知道该栏的名称是什么。 他们很想知道,为了说话,我所设计的栏目是他们所需要的,而不是我的名字和编号栏。

问题回答

您的表格中没有一栏“_id”,或你没有在问询中加入。 这是造成例外的原因。 你们还需要确定以下内容:

您对CrasorAdapter建筑商的最后论点没有提及_id。

The int[] argument is an array of view ids to populate with values from the cursor. The String[] argument is an array of column names from a row the cursor points to.

你们在阵列中必须拥有同等数量的价值观。 由于库尔斯的数据正在从库尔斯里取回,并且被带往这些观点。 如果每个阵列的数值不相等,则适应者会放弃一个例外,因为它没有适当的信息量来将数据绘制到意见中。

此外,据JavaDoc 简单的CursorAdapter称,该建筑商之所以被解职,是因为造成问题在ID的深层进行。 坏处。 而是使用:

http://developer.android.com/vis/android/widget/SimpleCursorAdapter.html#SimpleCursorAdapter%28android.content.Context,%20int,%20android.database.Cursor,%20java.lang.String[],%20int[],%20int%29

简单的固定办法是在理由清单的末尾添加“0”。

如果你试图在安的列斯申请中使用现有的qlite数据库,那么你需要做一些预先准备的工作,以便妥善工作。 这个博客员额详细描述了这一进程。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签