2

我开发了一个应用程序。然后我在我的应用程序代码中下载并运行 Eclipse 上的查找错误工具,我得到以下错误:

Bug: Write to static field 
com.abc.myapp.controllers.LoginScreenActivityController.loginDetailsCursor from instance method   
com.abc.myapp.controllers.LoginScreenActivityController.getLoginMasterData()

This instance method writes to a static field. This is tricky to get correct if multiple instances are being manipulated, and generally bad practice. 

Confidence: High, Rank: Of Concern (15)
Pattern: ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD 
Type: ST, Category: STYLE (Dodgy code)

我收到错误的代码如下:

public class LoginScreenActivityController extends Activity{
    public static Cursor loginDetailsCursor;
    DatabaseHelper database_helper;
    public LoginScreenActivityController() {
    }

    public ArrayList<Login_Master> getLoginMasterData(){
        database_helper = new DatabaseHelper(this);
        try{
            database_helper.openDataBase();
        } catch (Exception e){
            e.printStackTrace();
        }   

                /*
                *
                * **Getting **bug** here**
                *
                */
        loginDetailsCursor = database_helper.getLoginDetails();

        //Creating instance of class Login_Master model
        Login_Master login_master = new Login_Master();
        ArrayList<Login_Master> loginDetailsArrayList = new ArrayList<Login_Master>();
        if(loginDetailsCursor != null && loginDetailsCursor.getCount()>0 ){
            for(loginDetailsCursor.moveToFirst(); !loginDetailsCursor.isAfterLast(); loginDetailsCursor.moveToNext()){
                //Done Some thing .....
            }
        }else{
            //Done some thing ...
        }

        //Closing Data Base Connection.
        if (database_helper != null) 
            database_helper.close();

        return loginDetailsArrayList;       
    }

    public void updateLoginDetails(String username){
        try{
            database_helper.openDataBase();
        } catch (Exception e){
        e.printStackTrace();
        }

        database_helper.updateLoginTab(username);
        //Closing Data Base Connection.

                /*
                *
                *  **Getting **null check bug** here**
                *
                */
        if (database_helper != null) 
            database_helper.close();
    }   
}

我应该怎么做才能删除这个错误。请给我建议。

4

0 回答 0