2

first of all, please any one can tell me is it possible to inflate a view without XML ?

Description is like this:
I have dynamically generated a view hierarchy by coding, like

Relative layout contain 4 Linear layouts
-1st Linear Layout contain Image View
-2nd Linear Layout contain surface view
-3rd Linear Layout contain Button
-4th Linear Layout contain Text Box

and there is no issue in generating all view / view hierarchy (I tested by debugging and inspecting child views)

But I am not able to set it as a setContent()
Because I don't have XML and not allowed to use XML(not sure why), i.e. I have no access of R.Layout. So I cant use inflater.Inflate(R.Layout...)

When I am setting main relative layout as a content, I am getting following error

12-16 11:32:03.653: E/AndroidRuntime(22564): java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package.class}: android.content.res.Resources$NotFoundException: Resource ID #0x1d97b

Anyone have any idea ?

----Updated Log----
12-16 12:33:16.143: E/AndroidRuntime(25358): FATAL EXCEPTION: main 12-16 12:33:16.143: E/AndroidRuntime(25358): java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package.class}: android.content.res.Resources$NotFoundException: Resource ID #0x1d97b 12-16 12:33:16.143: E/AndroidRuntime(25358): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343) 12-16 12:33:16.143: E/AndroidRuntime(25358): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395) 12-16 12:33:16.143: E/AndroidRuntime(25358): at android.app.ActivityThread.access$600(ActivityThread.java:162) 12-16 12:33:16.143: E/AndroidRuntime(25358): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364) 12-16 12:33:16.143: E/AndroidRuntime(25358): at android.os.Handler.dispatchMessage(Handler.java:107) 12-16 12:33:16.143: E/AndroidRuntime(25358): at android.os.Looper.loop(Looper.java:194) 12-16 12:33:16.143: E/AndroidRuntime(25358): at android.app.ActivityThread.main(ActivityThread.java:5371) 12-16 12:33:16.143: E/AndroidRuntime(25358): at java.lang.reflect.Method.invokeNative(Native Method) 12-16 12:33:16.143: E/AndroidRuntime(25358): at java.lang.reflect.Method.invoke(Method.java:525) 12-16 12:33:16.143: E/AndroidRuntime(25358): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 12-16 12:33:16.143: E/AndroidRuntime(25358): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 12-16 12:33:16.143: E/AndroidRuntime(25358): at dalvik.system.NativeStart.main(Native Method) 12-16 12:33:16.143: E/AndroidRuntime(25358): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x1d97b
hope it might help you to understand a bit more

---Dropbox link of my activity class which generate views---
https://www.dropbox.com/s/vclymo0cs0zp360/ScannerActivity.java?dl=0

akash kubavat
  • 847
  • 6
  • 17
  • 2
    Couple of questions: 1. Why can't you define your views in xml 2. Can you post your code on how you are creating and setting these views? – Naveed Dec 15 '14 at 22:54
  • "I am getting following error" -- if you want help with this, you will need to edit your question to include the full stack trace and the code involved in creating the layout. We have no means of helping you otherwise with this. – CommonsWare Dec 15 '14 at 23:17
  • @CommonsWare thanks for reply, I updated my original question with full logcat and source file is attached..FYI, my activity is extending **CaptureActivity** which is from 3rd party jar library and it is setting that layout from abstract methods.. – akash kubavat Dec 15 '14 at 23:44
  • You will have to get your support from the author of that `CaptureActivity`, whatever it is. – CommonsWare Dec 15 '14 at 23:51

2 Answers2

7

is it possible to inflate a view without XML ?

No. The definition of the term "inflation" in Android is to convert an XML resource file into a corresponding tree of Java objects. Layout inflation converts an XML layout resource into a corresponding tree of View objects.

But I am not able to set it as a setContent()

I do not know what setContent() method it is that you are referring to. To put a View as the main content of an Activity, use setContentView().

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
-1

There is something wrong with your xml layout thats why you are not able to access R.layout, do Build-->clean and see if there is any error in your xml layout or post your xml here.

kj007
  • 6,073
  • 4
  • 29
  • 47