Java 字符串与 BaseColumns._ID 连接会带来错误

发布于 2024-12-02 12:43:32 字数 629 浏览 0 评论 0原文

在 Eclipse 中,当我输入以下内容时:

BaseColumns._ID, + "=?"

我得到:

The operator + is undefined for the argument type(s) String

这怎么可能,它们都是字符串,不是吗?

现在这里是 BaseColumns._ID 的文档:

public static final String _ID

我正在编写的代码是:

public void deteleProfile(Long id) throws SQLException {
        SQLiteDatabase db = helper.getWritableDatabase();
        Integer i = db.delete(ProlificDatabase.TABLE, BaseColumns._ID, + "=?", new String[] {id.toString()});
        Log.d(TAG, i + " records deleted where id is " + id);

In eclipse as soon as i type this out:

BaseColumns._ID, + "=?"

I get:

The operator + is undefined for the argument type(s) String

How is that possible, they are both Strings aren't they?

now here is documentation for BaseColumns._ID:

public static final String _ID

the code I am writing is:

public void deteleProfile(Long id) throws SQLException {
        SQLiteDatabase db = helper.getWritableDatabase();
        Integer i = db.delete(ProlificDatabase.TABLE, BaseColumns._ID, + "=?", new String[] {id.toString()});
        Log.d(TAG, i + " records deleted where id is " + id);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浪漫之都 2024-12-09 12:43:32

你有一个流氓逗号:

BaseColumns._ID, + "=?"

应该是否则

BaseColumns._ID + "=?

它会尝试使用 + "=?" 作为独立参数,而 + 充当 一元运算符。

You've got a rogue comma:

BaseColumns._ID, + "=?"

should probably be

BaseColumns._ID + "=?

Otherwise it's trying to use + "=?" as a stand-alone argument with the + acting as a unary operator.

自由如风 2024-12-09 12:43:32

您的意思是 BaseColumns._ID + "=?" 而不是 BaseColumns._ID, + "=?" 吗?

编译器只会将 + 运算符的左侧视为空。

Do you mean BaseColumns._ID + "=?" instead of BaseColumns._ID, + "=?"?

The compiler just sees the left hand side of the + operator as being empty.

穿透光 2024-12-09 12:43:32

请参阅 文档介绍如何使用 db.delete 方法。而不是 BaseColumns._ID,+“=?” - 你应该这样做:

Integer i = db.delete(ProlificDatabase.TABLE, BaseColumns._ID + "=?", new String[] {id.toString()});

See this documentation on how to use the db.delete method. Instead of BaseColumns._ID, + "=?" - you should be doing this:

Integer i = db.delete(ProlificDatabase.TABLE, BaseColumns._ID + "=?", new String[] {id.toString()});
蘑菇王子 2024-12-09 12:43:32

可爱的额外(逗号)...喜欢逗号的本质,它意味着表达式和痛苦之间的分隔符...当你忽略它们时!

Lovely extra , (comma)... love the commas for what they are, meaning a separator between expressions and a pain ... for when you overlook them!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文