List of usage examples for java.lang ClassCastException ClassCastException
public ClassCastException(String s)
ClassCastException
with the specified detail message. From source file:Main.java
/** * This constructs an <code>Iterator</code> over each day in a date * range defined by a focus date and range style. * * For instance, passing Thursday, July 4, 2002 and a * <code>RANGE_MONTH_SUNDAY</code> will return an <code>Iterator</code> * that starts with Sunday, June 30, 2002 and ends with Saturday, August 3, * 2002, returning a Calendar instance for each intermediate day. * * @param focus the date to work with, either * <code>Date</code> or <code>Calendar</code> * @param rangeStyle the style constant to use. Must be one of the range * styles listed for the {@link #iterator(Calendar, int)} method. * @return the date iterator/*from ww w . java 2 s .c o m*/ * @throws IllegalArgumentException if the date * is <code>null</code> * @throws ClassCastException if the object type is * not a <code>Date</code> or <code>Calendar</code> */ public static Iterator iterator(Object focus, int rangeStyle) { if (focus == null) { throw new IllegalArgumentException("The date must not be null"); } if (focus instanceof Date) { return iterator((Date) focus, rangeStyle); } else if (focus instanceof Calendar) { return iterator((Calendar) focus, rangeStyle); } else { throw new ClassCastException("Could not iterate based on " + focus); } }
From source file:com.bangz.smartmute.NavigationDrawerFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {/*from w w w .j a va 2 s . co m*/ mCallbacks = (NavigationDrawerCallbacks) activity; Bundle args = getArguments(); if (args != null) mCurrentSelectedPosition = args.getInt(ARGUMENTS_POSITION, 0); } catch (ClassCastException e) { throw new ClassCastException("Activity must implement NavigationDrawerCallbacks."); } }
From source file:cn.tycoon.lighttrans.fileManager.AbstractFilePickerFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {// w w w . j a va2 s . c o m mListener = (OnFilePickedListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnFilePickedListener"); } }
From source file:com.ericbarnhill.arrayMath.MathArrayDouble1D.java
protected MathArrayDouble1D subtractC(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); }
From source file:com.ericbarnhill.arrayMath.MathArrayDouble2D.java
protected MathArrayDouble2D subtractC(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); }
From source file:com.ericbarnhill.arrayMath.MathArrayDouble3D.java
protected MathArrayDouble3D subtractC(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); }
From source file:org.apache.syncope.core.persistence.beans.user.SyncopeUser.java
@Override public <T extends AbstractDerAttr> boolean addDerivedAttribute(final T derivedAttribute) { if (!(derivedAttribute instanceof UDerAttr)) { throw new ClassCastException( "attribute is expected to be typed UDerAttr: " + derivedAttribute.getClass().getName()); }/*w ww . j a v a 2s . c om*/ return derivedAttributes.add((UDerAttr) derivedAttribute); }
From source file:net.java.sip.communicator.impl.protocol.jabber.OperationSetServerStoredAccountInfoJabberImpl.java
/** * Replaces the currentDetailValue detail with newDetailValue and returns * true if the operation was a success or false if currentDetailValue did * not previously exist (in this case an additional call to addDetail is * required)./*w w w . jav a 2 s. co m*/ * <p> * @param currentDetailValue the detail value we'd like to replace. * @param newDetailValue the value of the detail that we'd like to replace * currentDetailValue with. * @return true if the operation was a success or false if * currentDetailValue did not previously exist (in this case an additional * call to addDetail is required). * @throws ClassCastException if newDetailValue is not an instance of the * same class as currentDetailValue. */ public boolean replaceDetail(ServerStoredDetails.GenericDetail currentDetailValue, ServerStoredDetails.GenericDetail newDetailValue) throws ClassCastException { if (!newDetailValue.getClass().equals(currentDetailValue.getClass())) { throw new ClassCastException("New value to be replaced is not as the current one"); } // if values are the same no change if (currentDetailValue.equals(newDetailValue)) { return true; } boolean isFound = false; Iterator<GenericDetail> iter = infoRetreiver.getDetails(uin, currentDetailValue.getClass()); while (iter.hasNext()) { GenericDetail item = iter.next(); if (item.equals(currentDetailValue)) { isFound = true; break; } } // current detail value does not exist if (!isFound) { return false; } removeDetail(currentDetailValue); addDetail(newDetailValue); return true; }
From source file:com.ebaotech.salesplatform.commons.helper.SimpleSharedPreferences.java
@Override public float getFloat(String key, float defValue) throws ClassCastException { initiateSharedPreferences();/* www. j a v a 2 s . c om*/ try { return mSharedPreferences.getFloat(key, defValue); } catch (final ClassCastException e) { final String returnType = new Object() { }.getClass().getEnclosingMethod().getReturnType().toString(); throw new ClassCastException("\n ======================================== \nClassCastException : " + key + "'s value is not a " + returnType + " \n ======================================== \n"); } }