• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Layout inflate - Illegal State Exception

assistant

Lurker
Hi,

I have two TextView array I want to display. The size of array is dynamic but is always the same for both. For every text view I have separate XML layout file.

The code is going like this pretty much:

Code:
....
 
 
[SIZE=2]LinearLayout layout = [/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] LinearLayout([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]);[/SIZE][/LEFT]
 
[LEFT][SIZE=2]layout.setOrientation(1);[/SIZE][/LEFT]
 
[LEFT][SIZE=2]....[/SIZE][/LEFT]
 
 
 
[LEFT][SIZE=2]TextView name[];[/SIZE][/LEFT]
 
 
 
[LEFT][SIZE=2]TextView value[];[/SIZE][/LEFT]
 
 
 
[LEFT][SIZE=2][SIZE=2]View NAME = [/SIZE][/SIZE][SIZE=2][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].getLayoutInflater().inflate(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]name[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], layout);[/SIZE][/SIZE]
[SIZE=2][SIZE=2]View VALUE = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].getLayoutInflater().inflate(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]value[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], layout);[/SIZE][/SIZE][/LEFT]
 
 
[LEFT].....[/LEFT]
 
[LEFT]for (i=0; i < SIZE_OF_ARRAY; i++)
{[/LEFT]
 
 
[LEFT][SIZE=2]name [i] [I][I][I]= (TextView)NAME.findViewById(R.id.[/I][/I][/I][/SIZE][I][I][I][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]name[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE][/I][/I][/I]
[SIZE=2]value [i] = [I](TextView)VALUE.findViewById(R.id.[/I][/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]value[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE][/I][/LEFT]
 
[LEFT][SIZE=2]....[/SIZE][/LEFT]
 
[LEFT][SIZE=2]name[i].setText("1234");[/SIZE]
[SIZE=2]value[i].setText("ABCD")[/SIZE][SIZE=2];[/SIZE][/LEFT]
 
[LEFT][SIZE=2]....[/SIZE][/LEFT]
 
[LEFT][SIZE=2]layout.addView( name[i] );[/SIZE]
[SIZE=2][SIZE=2]layout.addView( value[i] );[/SIZE][/SIZE]
}[/LEFT]
 
[LEFT]setContentView(layout);[/LEFT]

It's throwing illegal state exception.​

Please help. Thanks in advance.​
 
Back
Top Bottom