java - Android: Identical lines of code not working in seperate methods -


if happen use few lines of code in same method construction of called variables, works, if create method the same operation, copy-pasted , call other method inside it, wouldn't work.

    private void initelements(){      textview agevalue[] =             {                     (textview)this.findviewbyid(r.id.age1value),                     (textview)this.findviewbyid(r.id.age2value),                     (textview)this.findviewbyid(r.id.age3value)             };      textview agetext[] =             {                     (textview)this.findviewbyid(r.id.age1text),                     (textview)this.findviewbyid(r.id.age2text),                     (textview)this.findviewbyid(r.id.age3text)             };              for(int = 0; i<=2;i++){           intvalues[i] = a.gethours((i));         stringvalues[i] = string.valueof(intvalues[i]);         agevalue[i].settext(stringvalues[i]);      }      //updatevalues();  }  private void updatevalues(){                   for(int = 0; i<=2;i++){           intvalues[i] = a.gethours((i));         stringvalues[i] = string.valueof(intvalues[i]);         agevalue[i].settext(stringvalues[i]);      }        } 

if uncomment updatevalues() function, program wouldn't run, though same code executed in function before. moreover, debugging lead after statement:

        agevalue[i].settext(stringvalues[i]); 

to error

i've tried rebuilding , cleaning program , reinstalling it. tried on virtual device , real smartphone. same error on , over. (moreover, says "source code not match bytecode" when hover on error in picture, doesn't." tried "this." keyword everywhere, no success.

i baffled how happen. maybe method not sort of right memory reference because not directly next declaration mean 2 statements before "error statement" work fine, despite them having same nature. great if enlighten me why not work, thanks!

    textview agevalue[] = new textview[3]; textview agetext[] = new textview[3];  int intvalues[] = new int[3]; string stringvalues[] = new string[3];  calculatedates = new calculatedates(); 

this declaration of used variables. (that's in beginning of class)

you need use global agevalue[] , agetext[] class.

private void initelements(){      agevalue[0] =(textview)this.findviewbyid(r.id.age1value);     agevalue[1] =(textview)this.findviewbyid(r.id.age2value);     agevalue[2] =(textview)this.findviewbyid(r.id.age3value);      agetext[0] = (textview)this.findviewbyid(r.id.age1text);    agetext[1] = (textview)this.findviewbyid(r.id.age2text);    agetext[2] = (textview)this.findviewbyid(r.id.age3text);            for(int = 0; i<=2;i++){       intvalues[i] = a.gethours((i));     stringvalues[i] = string.valueof(intvalues[i]);     agevalue[i].settext(stringvalues[i]);  } 

do not declare textviews inside method also.

you creating different instances of textviews in initelements() method , global textviews still null


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -