简体   繁体   中英

Suspicious indentation: This is indented but is not continuing the previous expression

Android studio showing me this issue with red line below my code line

"Suspicious indentation: This is indented but is not continuing the previous expression (binding.cllInte.netA...) (Previous statement here)"

显示问题时的 Android Studio 屏幕截图

override fun onResume() {
    super.onResume()
    //Clear search edit text
    binding.etSearch.text?.clear()

    lookUpNumberVM.isInternetLiveData.observe(viewLifecycleOwner) {
        if (it) {
            binding.cllMain.visibility = View.VISIBLE
            binding.cllInternetAvailability.visibility = View.GONE
        } else {
            binding.cllMain.visibility = View.GONE
            binding.cllInternetAvailability.visibility = View.VISIBLE
              makeSnackBar(binding.root,"No internet connection")
        }
    }
}

my code is above and you can see issue in screenshot attachecd with question. I will really appreciate your efforts.

As hata pointed out in his commentary, it's probably the additional intendation (+2 spaces) of the makeSnackBar line. Note, that you can avoid such problems in a general way by ending your code statements with a semicolon, which is usually recommended. This also improves readability. So:

override fun onResume() {
    super.onResume();
    //Clear search edit text
    binding.etSearch.text?.clear();

    lookUpNumberVM.isInternetLiveData.observe(viewLifecycleOwner) {
        if (it) {
            binding.cllMain.visibility = View.VISIBLE;
            binding.cllInternetAvailability.visibility = View.GONE;
        } else {
            binding.cllMain.visibility = View.GONE;
            binding.cllInternetAvailability.visibility = View.VISIBLE;
            makeSnackBar(binding.root,"No internet connection");
        }
    }
}

Thereby intendation wouldn't play a role anymore (except for readability of course, so keep using intendations) as the compiler has now unambigious information about where a code statement begins and ends.

Simply Use

ctrl+Alt+L

All will be fine Cheers:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM