.equal () doesn't work as expected

btntxt=alphbtn[0].getText().toString();
cntr=cnt;
Log.i("Chr", "" + cnt + " " + crtchr);
for (int i = 0; i<strlnth ; i++)
{
    crtchr=(String.valueOf(curntnam.charAt(i)));
    if (strlnth > 8 && i==7)
    {
        i++;
    }
    if (btntxt.equals((crtchr)))
    {
        bt[i].setText(crtchr);
        cnt++;
    }
    Log.i("Chr", ""+crtchr);}
    Log.i("BUTTN", ""+btntxt);
}

      

In the above code, I want to compare the string with the button text, which is az on each button respectively. I am using a button array to store all 26 alphabet buttons. When it curntnam

contains an 8 character word, it works correctly, but when the word characters exceed 8, the app crashes and logs in and out of the loop so that the message appears in the logarithm correctly. When I click on the error it will show me the error in

if (btntxt.equals((crtchr))){

So what do I need to do to make it correct for more than 8 characters? Please help me, my application has finished but this error is preventing me from finishing.

+3


source to share


2 answers


btntxt

should be empty if this line gives you an error. The control btntxt

is null or registers this variable for the control.



0


source


There was a bug in my code where the for loop was called after 8, so it crashed the application. Now I have solved my problem.



0


source







All Articles