【问题标题】:How to fix "Cursor hides a field"?如何修复“光标隐藏字段”?
【发布时间】:2013-09-15 01:31:35
【问题描述】:

我有一个 SQLite 查询:

private String showAllType = "select * from tbl_Type";

我这样称呼它:

Cursor mCursor = mSQLiteDB.rawQuery(showAllType, null);

但是当我检查代码样式时,它会发出警告:'mCursor' hides a field' 我该如何解决这个问题?

【问题讨论】:

    标签: java coding-style checkstyle


    【解决方案1】:

    错误消息表明,您正在使用与私有定义字段同名的局部变量。这是糟糕的代码设计,应该避免。

    将新的Cursor 变量重命名为其他变量。 mSomething 通常用于字段,而不是局部变量。

    改用cursor

    Cursor cursor = mSQLiteDB.rawQuery(showAllType, null);
    // use 'cursor' for all the actions below
    

    【讨论】:

    • 非常感谢 FLX。我看到了问题!因为我定义了一个总变量:Cursor mCursor = null;警告也是如此
    • 嘿@user2760991,如果你想让人们回答你的问题,你应该接受他们。这与您的其他问题相同。否则人们会停止回答你的。只需按此箭头即可使其变为绿色。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-25
    • 2011-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 1970-01-01
    相关资源
    最近更新 更多