1. Download our Official Android App: Forums for Android!

Apps Layout inflate - Illegal State Exception

Discussion in 'Android Development' started by assistant, Apr 7, 2011.

  1. assistant

    assistant Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    9
    Joined:
    Feb 20, 2011

    Feb 20, 2011
    9
    0
    5
    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 (Text):
    1.  
    2. ....
    3.  
    4.  
    5. [SIZE=2]LinearLayout layout = [/SIZE]
    6. [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]
    7.  
    8. [LEFT][SIZE=2]layout.setOrientation(1);[/SIZE][/LEFT]
    9.  
    10. [LEFT][SIZE=2]....[/SIZE][/LEFT]
    11.  
    12.  
    13.  
    14. [LEFT][SIZE=2]TextView name[];[/SIZE][/LEFT]
    15.  
    16.  
    17.  
    18. [LEFT][SIZE=2]TextView value[];[/SIZE][/LEFT]
    19.  
    20.  
    21.  
    22. [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]
    23. [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]
    24.  
    25.  
    26. [LEFT].....[/LEFT]
    27.  
    28. [LEFT]for (i=0; i < SIZE_OF_ARRAY; i++)
    29. {[/LEFT]
    30.  
    31.  
    32. [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]
    33. [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]
    34.  
    35. [LEFT][SIZE=2]....[/SIZE][/LEFT]
    36.  
    37. [LEFT][SIZE=2]name[i].setText("1234");[/SIZE]
    38. [SIZE=2]value[i].setText("ABCD")[/SIZE][SIZE=2];[/SIZE][/LEFT]
    39.  
    40. [LEFT][SIZE=2]....[/SIZE][/LEFT]
    41.  
    42. [LEFT][SIZE=2]layout.addView( name[i] );[/SIZE]
    43. [SIZE=2][SIZE=2]layout.addView( value[i] );[/SIZE][/SIZE]
    44. }[/LEFT]
    45.  
    46. [LEFT]setContentView(layout);[/LEFT]
    47.  
    It's throwing illegal state exception.​

    Please help. Thanks in advance.​
     

    Advertisement

Share This Page

Loading...