Resources$NotFoundException error


Last Updated:

  1. Lintz

    Lintz Member

    I'm getting a Resources$NotFoundException error when attempting to write text to a TextView after I have clicked on a button.

    If I update the text within the click event it works OK but as soon as I attempt to update the text in a different method (called from within the click event) the error occurs.

    Can someone help me solve this issue as I've been going round in circles on this for ages. Below is my code.

    Thanks.

    Code (Text):
    1.     /** Called when the activity is first created. */
    2.     @Override
    3.     public void onCreate(Bundle savedInstanceState) {
    4.         super.onCreate(savedInstanceState);
    5.        
    6.         setContentView(R.layout.main);
    7.        
    8.         Button buttonCancel = (Button) findViewById(R.id.get_usage);
    9.         buttonCancel.setOnClickListener(new OnClickListener() {
    10.         @Override
    11.             public void onClick(View v) {
    12.            
    13.        //The TextView updates fine if placed here
    14.         TextView tv = (TextView) findViewById(R.id.Usage);
    15.         tv.setText("Test123"); // updates OK without error
    16.  
    17.            //The error occurs in this method
    18.             UpdateGUIWithUsageInformation("Testing123");
    19.  
    20.         });
    21.     }
    22.  
    23.  private void UpdateGUIWithUsageInformation(String newText)
    24.     {
    25.        
    26.         //Current Usage
    27.         TextView tv = (TextView) findViewById(R.id.Usage);
    28.         tv.setText(newText); // Error occurs on this line
    29. }
    30.  
    This is from my main.xml.
    Code (Text):
    1. <TextView
    2.     android:text=""
    3.     android:id="@+id/Usage"
    4.     android:layout_width="wrap_content"
    5.     android:layout_height="wrap_content">
    6.     </TextView>

    Advertisement

Share This Page