Example usage for java.lang ClassCastException ClassCastException

List of usage examples for java.lang ClassCastException ClassCastException

Introduction

In this page you can find the example usage for java.lang ClassCastException ClassCastException.

Prototype

public ClassCastException(String s) 

Source Link

Document

Constructs a ClassCastException with the specified detail message.

Usage

From source file:at.wada811.app.fragment.VideoFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    LogUtils.i();/*from w  ww .  j  a v a 2  s . co  m*/

    if (activity instanceof VideoCallbackProvider == false) {
        throw new ClassCastException("activity must implements VideoCallbackPicker.");
    }
    VideoCallbackProvider picker = (VideoCallbackProvider) activity;
    mCallback = picker.getVideoCallback();
}

From source file:it.iziozi.iziozi.gui.IOBoardFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {//  ww w  .j  av a2 s  .  c o  m
        mListener = (OnBoardFragmentInteractionListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement OnFragmentInteractionListener");
    }

    Log.d(LOG_TAG, "on attach!");
}

From source file:ca.uhn.fhir.model.api.ExtensionDt.java

/**
 * Returns the value of this extension, casted to a primitive datatype. This is a convenience method which should only be called if you are sure that the value for this particular extension will
 * be a primitive.//from  w  w w .j ava 2  s  .  c  om
 * <p>
 * Note that if this extension contains extensions (instead of a datatype) then <b>this method will return null</b>. In that case, you must use {@link #getUndeclaredExtensions()} and
 * {@link #getUndeclaredModifierExtensions()} to retrieve the child extensions.
 * </p>
 * 
 * @throws ClassCastException
 *             If the value of this extension is not a primitive datatype
 */
public IPrimitiveDatatype<?> getValueAsPrimitive() {
    if (!(getValue() instanceof IPrimitiveDatatype)) {
        throw new ClassCastException("Extension with URL[" + myUrl
                + "] can not be cast to primitive type, type is: " + getClass().getCanonicalName());
    }
    return (IPrimitiveDatatype<?>) getValue();
}

From source file:com.dabay6.android.apps.carlog.ui.base.fragments.BaseDetailFragment.java

/**
 * {@inheritDoc}/*from  ww w .  j av a 2 s .  c om*/
 */
@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    try {
        onEntityDetailListener = (OnEntityDetailListener) activity;
    } catch (final ClassCastException ex) {
        throw new ClassCastException(activity.toString() + " must implement OnEntityDetailListener");
    }
}

From source file:app.com.vaipo.VerifyPhoneFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // This makes sure that the container activity has implemented
    // the callback interface. If not, it throws an exception
    try {//from w w  w.  java 2  s  .c  o  m
        mCallback = (RegistrationVerificationListener) getActivity();
    } catch (ClassCastException e) {
        throw new ClassCastException(getActivity().toString() + " must implement LogoutUser");
    }

    appState = (AppState) getActivity().getApplication();
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());

    formatter.initialize();
    initCodes(getActivity());

    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mMessageReceiver,
            new IntentFilter(Utils.REGISTRATION_STATUS));
}

From source file:com.notepadlite.NoteListFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    // Verify that the host activity implements the callback interface
    try {/*  w  w  w .j av  a2  s  . com*/
        // Instantiate the Listener so we can send events to the host
        listener = (Listener) activity;
    } catch (ClassCastException e) {
        // The activity doesn't implement the interface, throw exception
        throw new ClassCastException(activity.toString() + " must implement Listener");
    }
}

From source file:com.boundlessgeo.geoserver.json.JSONWrapper.java

/**
 * Casts the wrapper to an object wrapper.
 *//* ww  w.j  a v a 2s .c  om*/
public JSONArr toArray() {
    if (this instanceof JSONArr) {
        return (JSONArr) this;
    }
    throw new ClassCastException("Not an array");
}

From source file:com.caseybrooks.scripturememory.fragments.HelpFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {//from   w w w  .java  2s . c  om
        mCallbacks = (NavigationCallbacks) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException("Activity must implement NavigationCallbacks.");
    }
}

From source file:com.xhsoft.framework.common.utils.ClassUtil.java

/**
 * //from w w  w  . j  av a  2  s .  c  o  m
 * @param className
 * @param parent
 * @return
 * @throws ClassNotFoundException
 * @throws InstantiationException
 * @throws IllegalAccessException - Object
 * @author: lizj
 */
public static Object getInstance(String className, Class<?> parent)
        throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    Class<?> clazz = ClassUtil.getClass(className);

    if (parent == null) {
        parent = Object.class;
    }

    if (!parent.isAssignableFrom(clazz)) {
        throw new ClassCastException(
                className + " class must be implement the " + parent.getName() + " interface.");
    }

    return clazz.newInstance();
}

From source file:com.royclarkson.springagram.PhotoListFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {/*from  w w  w  . j  a v  a2  s  .  c o m*/
        this.photoListFragmentListener = (PhotoListFragmentListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement OnPhotoSelectedListener");
    }
}