Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Working code:
EditText t1,t2,t3,t4,t5,t6,t7;
t1.setVisibility(View.VISIBLE);
     t2.setVisibility(View.VISIBLE);
     t3.setVisibility(View.VISIBLE);
     t4.setVisibility(View.VISIBLE);
     t5.setVisibility(View.VISIBLE);
     t6.setVisibility(View.VISIBLE);
     t7.setVisibility(View.VISIBLE);

Error code:
EditText[] t;
<pre>       t[0].setVisibility(View.VISIBLE);
                 t[1].setVisibility(View.VISIBLE);
                 t[2].setVisibility(View.VISIBLE);
                 t[3].setVisibility(View.VISIBLE);
                 t[4].setVisibility(View.VISIBLE);
                 t[5].setVisibility(View.VISIBLE);
                 t[6].setVisibility(View.VISIBLE);


What I have tried:

I have to use a lot of variables of EditText. So i am trying to use array of EditText so that in future i will use loop and reduce the code but its not working while using normally it works fine.Please help.
Posted
Updated 22-Sep-20 22:16pm
Comments
OriginalGriff 23-Sep-20 2:01am    
"It's not working" is one of the most useless problem descriptions we get: it tells us absolutely nothing about the problem. We don't know if you get an error message, or the wrong data, or even that that code compiles successfully!
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
So tell us what happens when you run that code, what you expected to happen, how you checked what happened. Help us to help you!
Use the "Improve question" widget to edit your question and provide better information.

1 solution

Java
EditText[] t;
t[0].setVisibility(View.VISIBLE);
t[1].setVisibility(View.VISIBLE);

You have created the array t, but it does not contain anything. So t[0], t[1] etc. do not exist. You must add references to actual EditText items in each entry that you are trying to use. Something like:
Java
EditText[] t = new EditText[6];
t[0] = new EditText;
t[0].setVisibility(View.VISIBLE);
 
Share this answer
 
Comments
Vivek Kansal 23-Sep-20 7:40am    
Thank you so much sir for your answer
Richard MacCutchan 23-Sep-20 8:54am    
You are welcome. Creating a loop should be quite simple.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900