在 android studio 中,我使用 SonarLint
来测试代码,我在 Activity 中遇到错误
make the enclosing method "static" or remove this set
我使用了在 onCreate
方法中使用的静态变量。
代码:
public class BaseActivity extends AppCompatActivity implements Interactor, UserMapView, RecyclerItemClickListener {
static LoginDao listLogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
progressBar = (ProgressBar) findViewById(R.id.progress_bar);
loginPresenter = new RecyclerviewPresenter();
loginPresenter.attachedView(this);
setupRecyclerView();
listLogin = DataProvider.getLoginDao(this);
}
public List < Login > createCollectionPictures() {
List < Login > pictures;
pictures = listLogin.loadAll();
return pictures;
}
Note: If I don't declare the static I couldn't get the output(variable listlogin should be null) but how to solve this error.
提前致谢。
最佳答案
我认为您应该为该静态变量创建一个 getter 方法,并在需要静态变量时使用该 getter 方法。这不会产生问题,并且会按预期工作。我希望这会对您有所帮助。
关于android - 我收到错误,使封闭方法 "static"或从 android 中的 SonarLint 中删除此集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39224302/