Search in sources :

Example 1 with InflateException

use of android.view.InflateException in project cw-omnibus by commonsguy.

the class MenuInflater method inflate.

/**
     * Inflate a menu hierarchy from the specified XML resource. Throws
     * {@link InflateException} if there is an error.
     *
     * @param menuRes Resource ID for an XML layout resource to load (e.g.,
     *            <code>R.menu.main_activity</code>)
     * @param menu The Menu to inflate into. The items and submenus will be
     *            added to this Menu.
     */
public void inflate(int menuRes, Menu menu) {
    XmlResourceParser parser = null;
    try {
        parser = mContext.getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs, menu);
    } catch (XmlPullParserException e) {
        throw new InflateException("Error inflating menu XML", e);
    } catch (IOException e) {
        throw new InflateException("Error inflating menu XML", e);
    } finally {
        if (parser != null)
            parser.close();
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet) InflateException(android.view.InflateException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 2 with InflateException

use of android.view.InflateException in project android_frameworks_base by ParanoidAndroid.

the class SimpleInflater method inflate.

public void inflate(int menuRes) {
    XmlResourceParser parser = null;
    try {
        parser = mContext.getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException e) {
        throw new InflateException("Error inflating menu XML", e);
    } catch (IOException e) {
        throw new InflateException("Error inflating menu XML", e);
    } finally {
        if (parser != null)
            parser.close();
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet) InflateException(android.view.InflateException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 3 with InflateException

use of android.view.InflateException in project android_frameworks_base by ParanoidAndroid.

the class BridgeInflater method createViewFromTag.

@Override
public View createViewFromTag(View parent, String name, AttributeSet attrs) {
    View view = null;
    try {
        view = super.createViewFromTag(parent, name, attrs);
    } catch (InflateException e) {
        // try to load the class from using the custom view loader
        try {
            view = loadCustomView(name, attrs);
        } catch (Exception e2) {
            // Wrap the real exception in an InflateException so that the calling
            // method can deal with it.
            InflateException exception = new InflateException();
            if (e2.getClass().equals(ClassNotFoundException.class) == false) {
                exception.initCause(e2);
            } else {
                exception.initCause(e);
            }
            throw exception;
        }
    }
    setupViewInContext(view, attrs);
    return view;
}
Also used : InflateException(android.view.InflateException) View(android.view.View) InflateException(android.view.InflateException)

Example 4 with InflateException

use of android.view.InflateException in project android_frameworks_base by ParanoidAndroid.

the class ActivityThread method performLaunchActivity.

private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) {
    // System.out.println("##### [" + System.currentTimeMillis() + "] ActivityThread.performLaunchActivity(" + r + ")");
    ActivityInfo aInfo = r.activityInfo;
    if (r.packageInfo == null) {
        r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, Context.CONTEXT_INCLUDE_CODE);
    }
    ComponentName component = r.intent.getComponent();
    if (component == null) {
        component = r.intent.resolveActivity(mInitialApplication.getPackageManager());
        r.intent.setComponent(component);
    }
    if (r.activityInfo.targetActivity != null) {
        component = new ComponentName(r.activityInfo.packageName, r.activityInfo.targetActivity);
    }
    Activity activity = null;
    try {
        java.lang.ClassLoader cl = r.packageInfo.getClassLoader();
        activity = mInstrumentation.newActivity(cl, component.getClassName(), r.intent);
        StrictMode.incrementExpectedActivityCount(activity.getClass());
        r.intent.setExtrasClassLoader(cl);
        if (r.state != null) {
            r.state.setClassLoader(cl);
        }
    } catch (Exception e) {
        if (!mInstrumentation.onException(activity, e)) {
            throw new RuntimeException("Unable to instantiate activity " + component + ": " + e.toString(), e);
        }
    }
    try {
        Application app = r.packageInfo.makeApplication(false, mInstrumentation);
        if (localLOGV)
            Slog.v(TAG, "Performing launch of " + r);
        if (localLOGV)
            Slog.v(TAG, r + ": app=" + app + ", appName=" + app.getPackageName() + ", pkg=" + r.packageInfo.getPackageName() + ", comp=" + r.intent.getComponent().toShortString() + ", dir=" + r.packageInfo.getAppDir());
        if (activity != null) {
            Context appContext = createBaseContextForActivity(r, activity);
            CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager());
            Configuration config = new Configuration(mCompatConfiguration);
            if (DEBUG_CONFIGURATION)
                Slog.v(TAG, "Launching activity " + r.activityInfo.name + " with config " + config);
            activity.attach(appContext, this, getInstrumentation(), r.token, r.ident, app, r.intent, r.activityInfo, title, r.parent, r.embeddedID, r.lastNonConfigurationInstances, config);
            if (customIntent != null) {
                activity.mIntent = customIntent;
            }
            r.lastNonConfigurationInstances = null;
            activity.mStartedActivity = false;
            int theme = r.activityInfo.getThemeResource();
            if (theme != 0) {
                activity.setTheme(theme);
            }
            activity.mCalled = false;
            mInstrumentation.callActivityOnCreate(activity, r.state);
            if (!activity.mCalled) {
                throw new SuperNotCalledException("Activity " + r.intent.getComponent().toShortString() + " did not call through to super.onCreate()");
            }
            r.activity = activity;
            r.stopped = true;
            if (!r.activity.mFinished) {
                activity.performStart();
                r.stopped = false;
            }
            if (!r.activity.mFinished) {
                if (r.state != null) {
                    mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state);
                }
            }
            if (!r.activity.mFinished) {
                activity.mCalled = false;
                mInstrumentation.callActivityOnPostCreate(activity, r.state);
                if (!activity.mCalled) {
                    throw new SuperNotCalledException("Activity " + r.intent.getComponent().toShortString() + " did not call through to super.onPostCreate()");
                }
            }
        }
        r.paused = true;
        mActivities.put(r.token, r);
    } catch (SuperNotCalledException e) {
        throw e;
    } catch (Exception e) {
        if (!mInstrumentation.onException(activity, e)) {
            if (e instanceof InflateException) {
                Log.e(TAG, "Failed to inflate", e);
                String pkg = null;
                if (r.packageInfo != null && !TextUtils.isEmpty(r.packageInfo.getPackageName())) {
                    pkg = r.packageInfo.getPackageName();
                }
                Intent intent = new Intent(Intent.ACTION_APP_LAUNCH_FAILURE, (pkg != null) ? Uri.fromParts("package", pkg, null) : null);
                getSystemContext().sendBroadcast(intent);
            }
            throw new RuntimeException("Unable to start activity " + component + ": " + e.toString(), e);
        }
    }
    return activity;
}
Also used : Context(android.content.Context) ActivityInfo(android.content.pm.ActivityInfo) Configuration(android.content.res.Configuration) Intent(android.content.Intent) InflateException(android.view.InflateException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) AndroidRuntimeException(android.util.AndroidRuntimeException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) AndroidRuntimeException(android.util.AndroidRuntimeException) InflateException(android.view.InflateException) ComponentName(android.content.ComponentName) java.lang(java.lang)

Example 5 with InflateException

use of android.view.InflateException in project android_frameworks_base by ParanoidAndroid.

the class GenericInflater method createItem.

/**
     * Low-level function for instantiating by name. This attempts to
     * instantiate class of the given <var>name</var> found in this
     * inflater's ClassLoader.
     * 
     * <p>
     * There are two things that can happen in an error case: either the
     * exception describing the error will be thrown, or a null will be
     * returned. You must deal with both possibilities -- the former will happen
     * the first time createItem() is called for a class of a particular name,
     * the latter every time there-after for that class name.
     * 
     * @param name The full name of the class to be instantiated.
     * @param attrs The XML attributes supplied for this instance.
     * 
     * @return The newly instantied item, or null.
     */
public final T createItem(String name, String prefix, AttributeSet attrs) throws ClassNotFoundException, InflateException {
    Constructor constructor = (Constructor) sConstructorMap.get(name);
    try {
        if (null == constructor) {
            // Class not found in the cache, see if it's real,
            // and try to add it
            Class clazz = mContext.getClassLoader().loadClass(prefix != null ? (prefix + name) : name);
            constructor = clazz.getConstructor(mConstructorSignature);
            sConstructorMap.put(name, constructor);
        }
        Object[] args = mConstructorArgs;
        args[1] = attrs;
        return (T) constructor.newInstance(args);
    } catch (NoSuchMethodException e) {
        InflateException ie = new InflateException(attrs.getPositionDescription() + ": Error inflating class " + (prefix != null ? (prefix + name) : name));
        ie.initCause(e);
        throw ie;
    } catch (ClassNotFoundException e) {
        // If loadClass fails, we should propagate the exception.
        throw e;
    } catch (Exception e) {
        InflateException ie = new InflateException(attrs.getPositionDescription() + ": Error inflating class " + constructor.getClass().getName());
        ie.initCause(e);
        throw ie;
    }
}
Also used : Constructor(java.lang.reflect.Constructor) InflateException(android.view.InflateException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) InflateException(android.view.InflateException) IOException(java.io.IOException)

Aggregations

InflateException (android.view.InflateException)100 IOException (java.io.IOException)51 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)48 AttributeSet (android.util.AttributeSet)30 XmlResourceParser (android.content.res.XmlResourceParser)19 Constructor (java.lang.reflect.Constructor)13 View (android.view.View)12 Path (android.graphics.Path)10 SuppressLint (android.annotation.SuppressLint)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 StringTokenizer (java.util.StringTokenizer)6 NonNull (android.annotation.NonNull)5 PathParser (android.util.PathParser)5 TypedValue (android.util.TypedValue)5 NonNull (android.support.annotation.NonNull)4 ExpandedMenuView (android.support.v7.internal.view.menu.ExpandedMenuView)4 ActionBarView (android.support.v7.internal.widget.ActionBarView)4 ViewGroup (android.view.ViewGroup)4 AlertDialog (android.app.AlertDialog)3 LayoutInflater (android.view.LayoutInflater)3