My issues is the following I’m trying to add a layout to a viewgroup my code goes like this:
View Dyn = (View) findViewById(R.id.lca1);
ViewGroup Layout1 = (ViewGroup) findViewById(R.id.l1);
View inflatedView = View.inflate(this, R.id.lcar1, null);
Layout1.addView(inflatedView);
My Logcat:
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): FATAL EXCEPTION: main
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.ViewFlipperExample}: android.content.res.Resources$NotFoundException: Resource ID #0x7f05002a type #0x12 is not valid
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at android.os.Looper.loop(Looper.java:123)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at java.lang.reflect.Method.invoke(Method.java:521)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at dalvik.system.NativeStart.main(Native Method)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f05002a type #0x12 is not valid
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1874)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at android.content.res.Resources.getLayout(Resources.java:731)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at android.view.View.inflate(View.java:8667)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at com.test.ViewFlipperExample.onCreate(ViewFlipperExample.java:66)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-05 19:01:02.019: ERROR/AndroidRuntime(26934): … 11 more
Any Help with this would help.
Thank you!!!!!!!
View inflatedView = View.inflate(this, R.id.lcar1, null); is wrong
you should inflate layout from res/layout folder (R.layout.lcar1 for example or any other)