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:br.com.expressobits.test.fragmentsui.HeadLinesFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    // This makes sure that the container activity has implemented
    // the callback interface. If not, it throws an exception.
    try {//from  ww  w  .  j ava 2  s  .c o  m
        mCallback = (OnHeadlineSelectedListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement OnHeadlineSelectedListener");
    }
}

From source file:com.brookmanholmes.bma.wizard.ui.ReviewFragment.java

@Override
public void onAttach(Context context) {
    super.onAttach(context);

    if (!(getActivity() instanceof Callbacks)) {
        throw new ClassCastException("Activity must implement fragment's callbacks");
    }/*from   w  ww  .  j  a va2 s. c  om*/

    callbacks = (Callbacks) getActivity();
}

From source file:com.navercorp.pinpoint.web.cluster.DefaultPinpointRouteResponse.java

@Override
public <R extends TBase> R getResponse(Class<R> clazz) {
    TBase response = getResponse();/*  www.  j  ava 2 s.com*/

    if (clazz.isInstance(response)) {
        return (R) response;
    }

    throw new ClassCastException("Not expected " + clazz + " type.");
}

From source file:CalendarUtils.java

/**
 * See the other round method.  Works with an Object, trying to
 * use it as either a Date or Calendar.//from   w w  w  .  j av a 2s.  c o  m
 */
public static Date round(Object val, int field) {
    if (val instanceof Date) {
        return round((Date) val, field);
    } else if (val instanceof Calendar) {
        return round((Calendar) val, field).getTime();
    } else {
        throw new ClassCastException("Could not round " + val);
    }
}

From source file:com.checktipsplitter.wizard.ui.FreeTextFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    if (!(((AppCompatActivity) activity).getSupportFragmentManager().getFragments()
            .get(0) instanceof PageFragmentCallbacks)) {
        throw new ClassCastException("Activity must implement PageFragmentCallbacks");
    }//ww w  . ja va2 s . c  o  m

    mCallbacks = (PageFragmentCallbacks) ((ActivityMain) activity).getSupportFragmentManager().getFragments()
            .get(0);
}

From source file:com.checktipsplitter.wizard.ui.ReviewFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    if (!(((AppCompatActivity) activity).getSupportFragmentManager().getFragments()
            .get(0) instanceof Callbacks)) {
        throw new ClassCastException("Activity must implement fragment's callbacks");
    }/*from w  ww.j a  v  a  2s. c om*/

    mCallbacks = (Callbacks) ((ActivityMain) activity).getSupportFragmentManager().getFragments().get(0);
    mWizardModel = mCallbacks.onGetModel();
    mWizardModel.registerListener(this);
    onPageTreeChanged();
}

From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.sign_trainer.AbstractSignTrainerFragment.java

@SuppressWarnings("deprecation") // necessary for API 15!
@Override/*from  ww  w.  j  av  a 2 s  . co m*/
public void onAttach(Activity activity) {
    Log.d(TAG, "onAttach " + hashCode());
    super.onAttach(activity);
    try {
        this.onToggleLearningModeListener = (OnToggleLearningModeListener) activity;
    } catch (ClassCastException ex) {
        throw new ClassCastException(activity.toString() + " must implement OnToggleLearningModeListener");
    }
}

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

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {/*from  w w w.j  a va 2  s.  c  o  m*/
        photoAddFragmentListener = (PhotoAddFragmentListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement PhotoAddFragmentListener");
    }
}

From source file:jp.terasoluna.fw.util.ConvertUtil.java

/**
 * ???//from  w  w w .j av  a2 s  . com
 * <ul>
 *   <li><code>null</code>?? - ?????<code>T</code>?????</li>
 *   <li><code>Object[]</code>?? - <code>T</code>??????</li>
 *   <li><code>Collection</code>?? - <code>T</code>?????</li>
 *   <li>???? - ?1???<code>T</code>?????</li>
 * </ul>
 * 
 * @param <E> ?????
 * @param obj 
 * @param elementClass ????? 
 * @return ???
 * @throws IllegalArgumentException <code>clazz</code>?
 *           <code>null</code>??
 *           <code>obj</code>?????????<code>T</code>
 *           ?????
 */
@SuppressWarnings("unchecked")
public static <E> List<E> toList(Object obj, Class<E> elementClass) throws IllegalArgumentException {
    if (elementClass == null) {
        throw new IllegalArgumentException("Argument 'elementClass' (" + Class.class.getName() + ") is null");
    }

    Object[] array = toArray(obj);
    List<E> result = new ArrayList<E>();
    for (Object element : array) {
        if (element != null && !elementClass.isAssignableFrom(element.getClass())) {
            String message = "Unable to cast '" + element.getClass().getName() + "' to '"
                    + elementClass.getName() + "'";
            throw new IllegalArgumentException(message, new ClassCastException(message));
        }
        result.add((E) element);
    }
    return result;
}

From source file:br.com.bioscada.apps.biotracks.fragments.ShareTrackDialogFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {/*from  w w  w. j  av a 2s. c  om*/
        caller = (ShareTrackCaller) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(
                activity.toString() + " must implement " + ShareTrackCaller.class.getSimpleName());
    }
}