6

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.cllInternetA...) (Previous statement here)"

Android studio screenshot while showing issue

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.

Assad khan
  • 161
  • 2
  • 9
  • 3
    The line of makeSnackBar is indented with two spaces for no reason. Try to delete these two spaces. – hata Dec 07 '22 at 09:21

3 Answers3

35

Simply Use

ctrl+Alt+L

All will be fine Cheers :)

Jadu
  • 489
  • 3
  • 10
1

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.

Krokomot
  • 3,208
  • 2
  • 4
  • 20
  • 1
    A semicolon a the end of a line doesn't improve anything. "The general rule in Kotlin is not to use semicolons." https://kotlincompact.com/no-semicolon.html – The incredible Jan Jan 06 '23 at 08:07
  • I admit, that even the official https://kotlinlang.org/docs/coding-conventions.html#semicolons recommends "Omit semicolons whenever possible." However neither here nor in your link it is elucidated why that should be in any way better or at least helpful. On the other side there are good reasons to use semicolons -- readabilty and less error susceptibility. – Krokomot Jan 06 '23 at 21:51
1

Help::5

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

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(adapter);

spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            end=parent.getItemAtPosition(position).toString();
                them.set(1,end);
                printDiametroPdf(them);
                if (position == 0) {
Nensi Kasundra
  • 1,980
  • 6
  • 21
  • 34
salvo
  • 11
  • 1