0

I have declared the method showTotalPoints(), but when it is called upon further down the code, Android Studio says it is a variable, not a method. It is indeed not in orange font (color for methods) but in grey font (color for unused variables). And a method that is being called should be in white font. Here it is in purple font, which again implies a variable.

Hovering the cursor over the code, the pop-up also confirms its a variable, not a method. I have declared (not shown, somewhere else in the code) another method calculateValues(), and that is properly interpreted as a method within the same curly braces.

Can someone please advise me on where I did a coding error?

 public void showTotalPoints(){
        textviewtpA.setText(String.valueOf(tpA));
        textviewtpB.setText(String.valueOf(tpB));
    }

 buttonWinnerA.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            winnersA = changeScore(winnersA, entry.isChecked());
            calculateValues();
            buttonWinnerA.setText(getString(R.string.winnner) + " (" + 
            String.valueOf(winnersA) + ")");
            showTotalPoints();
        }
    });

Here's a print-screen of the above code in Android Studio

Red Knight
  • 77
  • 7

2 Answers2

2

i think you declared showTotalPoints() in onCreate(). move it outside of onCreate()

TejpalBh
  • 427
  • 4
  • 13
  • You thought right. I had earlier experimented with shifting the declaration in and out of the onCreate () block, but that caused other problems (red font). But you're remark inspired me to break up the declaration and initiation of the variables textviewtpA and textviewtpB. The declaration is now outside that block, and it works! – Red Knight Jun 25 '18 at 13:08
  • @EvennessArts u can accept answer if this solved your issue :) – TejpalBh Jun 26 '18 at 12:29
1

You need to declared your showTotalPoints() outside of onCreate(). And you need to define your textviewtpA and textviewtpB as a global variable.

Mayur Patel
  • 2,300
  • 11
  • 30