title: R library in Android error
body: <p>I have been using this <a href="http://www.dummies.com/store/product/Android-Application-Development-For-Dummies.productCd-047077018X,navId-322496,descCd-DOWNLOAD.html" rel="nofollow">Android Guide</a></p>
  
  <p>While it has been a pleasant experience so far, I am experiencing my first problem. I copied all the code from the source that is in the link, and pasted it to the project folder, replacing all old files. <br><br>Before starting to understand what I had pasted, I thought it would be logical to run the code first to check for problems. The project wouldn't run because of an R object missing. After importing it (Eclipse's solution to the problem), more errors popped up. I tried searching for an answer, both on the Internet and in the book, but to no avail.<br><br> Since my software is up to date, I doubt this is a problem on the software's side. And since the code is available online, I think the problem would have popped up and been fixed. </p>
  
  <p>Thank you in advance for the help. For extra details please ask in the comments. </p>
  
  <pre><code>The code:
  
      MainActivity.java
  
          package com.dummies.android.silentmodetoggle;
  
          import android.app.Activity;
          import android.graphics.drawable.Drawable;
          import android.media.AudioManager;
          import android.os.Bundle;
          import android.util.Log;
          import android.view.View;
          import android.widget.Button;
          import android.widget.ImageView;
  
          public class MainActivity extends Activity {
  
          private AudioManager mAudioManager; 
          private boolean mPhoneIsSilent;
  
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.main);
  
              mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
  
              checkIfPhoneIsSilent(); 
  
              setButtonClickListener();
  
              Log.d("SilentModeApp", "This is a test");
          }    
  
          private void setButtonClickListener() {
           Button toggleButton = (Button)findViewById(R.id.toggleButton); 
           toggleButton.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  if (mPhoneIsSilent) {
                      // Change back to normal mode
                      mAudioManager
                              .setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                      mPhoneIsSilent = false;
                  } else {
                      // Change to silent mode
                      mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
                      mPhoneIsSilent = true;
                  }
  
                  // Now toggle the UI again
                  toggleUi();
              }
          }); 
         }
  
      /**
       * Checks to see if the phone is currently in silent mode. 
       */
      private void checkIfPhoneIsSilent() {
          int ringerMode = mAudioManager.getRingerMode();
          if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
              mPhoneIsSilent = true;
          } else {
              mPhoneIsSilent = false;
          }
  
      }
  
      /**
       * Toggles the UI images from silent
       * to normal and vice versa.
       */
      private void toggleUi() {
  
          ImageView imageView = 
              (ImageView) findViewById(R.id.phone_icon);
          Drawable newPhoneImage;
  
          if (mPhoneIsSilent) {
              newPhoneImage = 
                  getResources().getDrawable(R.drawable.phone_silent);
  
          } else {
              newPhoneImage = 
                  getResources().getDrawable(R.drawable.phone_on);
          }
  
          imageView.setImageDrawable(newPhoneImage);
      }
  
      @Override
      protected void onResume() {
          super.onResume();
          checkIfPhoneIsSilent();
          toggleUi();
      };
  }
  </code></pre>