title: How to use getResource.getIdentifier() to get Layout?
body: <p>I have a question,everyone.</p>
  
  <p>I want to use <code>getResource.getIdentifier()</code>  to get my layout element in XML (layout/xxx.xml).</p>
  
  <p>But I am encounter " Resource ID #0x7f070003 type #0x12 is not valid..." error message.</p>
  
  <p>I don't know how to fixed this problem.</p>
  
  <p>I am use a method return linearlayout. </p>
  
  <p>It's my code below:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  
   @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
  
    getWeekOfDay(2).setBackgroundColor(Color.RED);
   }
  
   private LinearLayout getWeekOfDay(int n)
   {
    int layoutID = getResources().getIdentifier("layout"+n, "id", getPackageName());
    return (LinearLayout) LayoutInflater.from(this).inflate(layoutID, null);
   }
  ....
  ...
  ..
  }
  </code></pre>
  
  <p>My layout have many linearlayout, but the name is similar(layout1, layout2, layout3...).</p>
  
  <p>I want to use call method get appoint element.</p>
  
  <p>my layout code is below:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/LinearLayout1"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      tools:context=".MainActivity" &gt;
  
      &lt;LinearLayout
          android:id="@+id/layout1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_weight="0.37"
          android:background="#cccccc" &gt;
  
              &lt;TextView
              android:id="@+id/TextView03"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="test1" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/layout2"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_weight="0.37"
          android:background="#cccccc" &gt;
  
          &lt;TextView
              android:id="@+id/TextView02"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="test2" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/layout3"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_weight="0.37"
          android:background="#cccccc" &gt;
  
          &lt;TextView
              android:id="@+id/TextView01"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="test3" /&gt;
  &lt;/LinearLayout&gt;
  
  &lt;LinearLayout
      android:id="@+id/layout4"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="0.37"
      android:background="#cccccc" &gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="test4" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>But the java code will return error .</p>
  
  <p>The error message is below :</p>
  
  <pre><code>      : FATAL EXCEPTION: main
       : java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testdemo/com.example.testdemo.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f070003 type #0x12 is not valid
       :  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2194)
       :  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)
       :  at android.app.ActivityThread.access$600(ActivityThread.java:139)
       :  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
       :  at android.os.Handler.dispatchMessage(Handler.java:99)
       :  at android.os.Looper.loop(Looper.java:154)
       :  at android.app.ActivityThread.main(ActivityThread.java:4945)
       :  at java.lang.reflect.Method.invokeNative(Native Method)
       :  at java.lang.reflect.Method.invoke(Method.java:511)
       :  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
       :  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
       :  at dalvik.system.NativeStart.main(Native Method)
       : Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070003 type #0x12 is not valid
       :  at android.content.res.Resources.loadXmlResourceParser(Resources.java:2358)
       :  at android.content.res.Resources.getLayout(Resources.java:952)
       :  at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
       :  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
       :  at com.example.testdemo.MainActivity.getWeekOfDay(MainActivity.java:25)
       :  at com.example.testdemo.MainActivity.onCreate(MainActivity.java:19)
       :  at android.app.Activity.performCreate(Activity.java:4531)
       :  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
       :  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2150)
       :  ... 11 more
  </code></pre>
  
  <p>Have anyone know this problem? How to resolve this problem?</p>