2

I have a complicated structure to be displayed on the screen. Made with XML layouts. For the vertical orientation and portrait layouts are different.

If you flip the screen layouts are redrawn and initializes the GUI. On the horizontal layout I use CustomRelativeLayout, in which overrides onMeasure ().

After a few quick revolutions display an error message from java.lang.RuntimeException: Unable to start activity ComponentInfo android.view.InflateException: Binary XML file line #146: Error inflating class This link goes to the element of my CustomRelativeLayout and lower Caused by: java.lang.reflect.InvocationTargetException with reference to the constructor of my custom class.

I suspect that activity simply has no time to be destroyed and start again, but how to fix it I have not the foggiest idea. I would be grateful for your help.

anaxdem
  • 23
  • 1
  • 6
  • are you using nested layouts? – kosa Jan 04 '12 at 14:58
  • Yes, I'm using nested layouts – anaxdem Jan 04 '12 at 15:02
  • View InflateException happens if you have too many nested view which is not supported by android. It is better change your approach in having nested views. How many nested views you have. – kosa Jan 04 '12 at 15:07
  • that is not the problem.you should paste more lines from the logcat. also the code that thrwos that error. – Ovidiu Latcu Jan 04 '12 at 15:15
  • I'm doing a complicated keyboard with symbols and complex components (actually my relativelayout). At the same time I do not want to hardcode the size of these components. To do this, and I use nested linearLayouts – anaxdem Jan 04 '12 at 15:18
  • Caused by: java.lang.reflect.InvocationTargetException at com.remotepanel.View.CustomRelativeLayout.(CustomRelativeLayout.java:14) at java.lang.reflect.Constructor.constructNative(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:446) at android.view.LayoutInflater.createView(LayoutInflater.java:500) – anaxdem Jan 04 '12 at 15:34
  • Here's code that throws eror: public CustomRelativeLayout(Context context, AttributeSet attrs) { super(context, attrs); } – anaxdem Jan 04 '12 at 15:34

1 Answers1

4

InvocationTargetException is a checked exception that wraps an exception thrown by an invoked method or constructor. The constructor of your custom class is throwing an exception. You need to look at the exception nested within the InvocationTargetException in order to figure out which exception your class is throwing.

piepera
  • 2,033
  • 1
  • 20
  • 21
  • How can I catch this exception? I do not call explicitly the constructor, is invoked when rendering layouts and in the class constructor can not put try / catch – anaxdem Jan 04 '12 at 15:10
  • Typically you'd diagnose this kind of problem by looking at the stack trace, you'd see something like 'Exception in thread "main" java.lang.reflect.InvocationTargetException... Caused by: java.lang.IOException'. Do you see any evidence of the nested exception within the InvocationTargetException? Is it possible for you to provide the entire stack trace? – piepera Jan 04 '12 at 15:38
  • I alspo se that android.view.InflateException: Binary XML file line #146: Error inflating class and this line is in xml layout file – anaxdem Jan 04 '12 at 15:42
  • If you can post the full stack trace, I feel like there's probably something else after the InvocationTargetException which will help a lot, similar to what was posted in this other question (http://stackoverflow.com/questions/6682730/android-android-view-inflateexception-binary-xml-file-line-13-error-inflatin) where the InvocationTargetException was wrapping a more specific error, about Looper.prepare() – piepera Jan 04 '12 at 21:19