diff options
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/view/LayoutInflater.java | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/core/java/android/view/LayoutInflater.java b/core/java/android/view/LayoutInflater.java index f13cb5a197d8..2e27737782fa 100644 --- a/core/java/android/view/LayoutInflater.java +++ b/core/java/android/view/LayoutInflater.java @@ -714,7 +714,8 @@ public abstract class LayoutInflater { ie.setStackTrace(EMPTY_STACK_TRACE); throw ie; } catch (Exception e) { - final InflateException ie = new InflateException(parser.getPositionDescription() + final InflateException ie = new InflateException( + getParserStateDescription(inflaterContext, attrs) + ": " + e.getMessage(), e); ie.setStackTrace(EMPTY_STACK_TRACE); throw ie; @@ -730,6 +731,16 @@ public abstract class LayoutInflater { } } + private static String getParserStateDescription(Context context, AttributeSet attrs) { + int sourceResId = Resources.getAttributeSetSourceResId(attrs); + if (sourceResId == Resources.ID_NULL) { + return attrs.getPositionDescription(); + } else { + return attrs.getPositionDescription() + " in " + + context.getResources().getResourceName(sourceResId); + } + } + private static final ClassLoader BOOT_CLASS_LOADER = LayoutInflater.class.getClassLoader(); private final boolean verifyClassLoader(Constructor<? extends View> constructor) { @@ -818,7 +829,7 @@ public abstract class LayoutInflater { if (mFilter != null && clazz != null) { boolean allowed = mFilter.onLoadClass(clazz); if (!allowed) { - failNotAllowed(name, prefix, attrs); + failNotAllowed(name, prefix, viewContext, attrs); } } constructor = clazz.getConstructor(mConstructorSignature); @@ -837,10 +848,10 @@ public abstract class LayoutInflater { boolean allowed = clazz != null && mFilter.onLoadClass(clazz); mFilterMap.put(name, allowed); if (!allowed) { - failNotAllowed(name, prefix, attrs); + failNotAllowed(name, prefix, viewContext, attrs); } } else if (allowedState.equals(Boolean.FALSE)) { - failNotAllowed(name, prefix, attrs); + failNotAllowed(name, prefix, viewContext, attrs); } } } @@ -862,14 +873,16 @@ public abstract class LayoutInflater { mConstructorArgs[0] = lastContext; } } catch (NoSuchMethodException e) { - final InflateException ie = new InflateException(attrs.getPositionDescription() + final InflateException ie = new InflateException( + getParserStateDescription(viewContext, attrs) + ": Error inflating class " + (prefix != null ? (prefix + name) : name), e); ie.setStackTrace(EMPTY_STACK_TRACE); throw ie; } catch (ClassCastException e) { // If loaded class is not a View subclass - final InflateException ie = new InflateException(attrs.getPositionDescription() + final InflateException ie = new InflateException( + getParserStateDescription(viewContext, attrs) + ": Class is not a View " + (prefix != null ? (prefix + name) : name), e); ie.setStackTrace(EMPTY_STACK_TRACE); throw ie; @@ -878,7 +891,7 @@ public abstract class LayoutInflater { throw e; } catch (Exception e) { final InflateException ie = new InflateException( - attrs.getPositionDescription() + ": Error inflating class " + getParserStateDescription(viewContext, attrs) + ": Error inflating class " + (clazz == null ? "<unknown>" : clazz.getName()), e); ie.setStackTrace(EMPTY_STACK_TRACE); throw ie; @@ -890,8 +903,8 @@ public abstract class LayoutInflater { /** * Throw an exception because the specified class is not allowed to be inflated. */ - private void failNotAllowed(String name, String prefix, AttributeSet attrs) { - throw new InflateException(attrs.getPositionDescription() + private void failNotAllowed(String name, String prefix, Context context, AttributeSet attrs) { + throw new InflateException(getParserStateDescription(context, attrs) + ": Class not allowed to be inflated "+ (prefix != null ? (prefix + name) : name)); } @@ -1013,13 +1026,15 @@ public abstract class LayoutInflater { throw e; } catch (ClassNotFoundException e) { - final InflateException ie = new InflateException(attrs.getPositionDescription() + final InflateException ie = new InflateException( + getParserStateDescription(context, attrs) + ": Error inflating class " + name, e); ie.setStackTrace(EMPTY_STACK_TRACE); throw ie; } catch (Exception e) { - final InflateException ie = new InflateException(attrs.getPositionDescription() + final InflateException ie = new InflateException( + getParserStateDescription(context, attrs) + ": Error inflating class " + name, e); ie.setStackTrace(EMPTY_STACK_TRACE); throw ie; @@ -1215,8 +1230,8 @@ public abstract class LayoutInflater { } if (type != XmlPullParser.START_TAG) { - throw new InflateException(childParser.getPositionDescription() + - ": No start tag found!"); + throw new InflateException(getParserStateDescription(context, childAttrs) + + ": No start tag found!"); } final String childName = childParser.getName(); |
