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:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.ui.common.NavigationDrawerFragment.java

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    try {//from  ww w. j  av a2  s . co  m
        mCallbacks = (NavigationDrawerCallbacks) getActivity();
    } catch (ClassCastException e) {
        throw new ClassCastException("Activity must implement NavigationDrawerCallbacks.");
    }
}

From source file:de.duenndns.ssl.MemorizingTrustManager.java

void init(Context m) {
    master = m;//from w  w w  .ja v a 2 s.  c  o  m
    masterHandler = new Handler(m.getMainLooper());
    notificationManager = (NotificationManager) master.getSystemService(Context.NOTIFICATION_SERVICE);

    Application app;
    if (m instanceof Application) {
        app = (Application) m;
    } else if (m instanceof Service) {
        app = ((Service) m).getApplication();
    } else if (m instanceof Activity) {
        app = ((Activity) m).getApplication();
    } else
        throw new ClassCastException("MemorizingTrustManager context must be either Activity or Service!");

    File dir = app.getDir(KEYSTORE_DIR, Context.MODE_PRIVATE);
    keyStoreFile = new File(dir + File.separator + KEYSTORE_FILE);

    poshCacheDir = app.getFilesDir().getAbsolutePath() + "/posh_cache/";

    appKeyStore = loadAppKeyStore();
}

From source file:net.sf.classifier4J.bayesian.WordProbability.java

public int compareTo(Object o) {
    if (!(o instanceof WordProbability)) {
        throw new ClassCastException(o.getClass() + " is not a " + this.getClass());
    }/*from   ww w  .ja va2 s .c om*/
    WordProbability rhs = (WordProbability) o;
    return new CompareToBuilder().append(this.getCategory(), rhs.getCategory())
            .append(this.getWord(), rhs.getWord()).toComparison();
}

From source file:com.gistlabs.mechanize.PageRequest.java

private Parameters extractParameters(final HttpEntity entity) {
    if (entity instanceof UrlEncodedFormEntity)
        return extractParameters((UrlEncodedFormEntity) entity);
    if (entity instanceof MultipartEntity)
        return extractParameters((MultipartEntity) entity);
    throw new ClassCastException(String
            .format("Can't convert %s to either UrlEncodedFormEntity or MultipartEntity", entity.getClass()));
}

From source file:com.projity.util.ClassUtils.java

/**
 * Get the corresponding object class from a primitive class
 * @param clazz primitive class//from  w ww  .  j  a va 2  s . c om
 * @return Object class.
 * @throws ClassCastException if class is unknown primitive
 */
public static Class primitiveToObjectClass(Class clazz) {
    //      return MethodUtils.toNonPrimitiveClass(clazz);
    if (clazz == Boolean.TYPE)
        return Boolean.class;
    else if (clazz == Character.TYPE)
        return Character.class;
    else if (clazz == Byte.TYPE)
        return Byte.class;
    else if (clazz == Short.TYPE)
        return Short.class;
    else if (clazz == Integer.TYPE)
        return Integer.class;
    else if (clazz == Long.TYPE)
        return Long.class;
    else if (clazz == Float.TYPE)
        return Float.class;
    else if (clazz == Double.TYPE)
        return Double.class;
    throw new ClassCastException("Cannot convert class" + clazz + " to an object class");
}

From source file:com.ericbarnhill.arrayMath.MathArrayFloat1D.java

protected MathArrayFloat1D multiply(Complex g) {
    throw new ClassCastException("Cannot multiply Complex number to double array");
}

From source file:com.ericbarnhill.arrayMath.MathArrayFloat2D.java

protected MathArrayFloat2D multiply(Complex g) {
    throw new ClassCastException("Cannot multiply Complex number to double array");
}

From source file:com.ericbarnhill.arrayMath.MathArrayFloat3D.java

protected MathArrayFloat3D multiply(Complex g) {
    throw new ClassCastException("Cannot multiply Complex number to double array");
}

From source file:com.microsoft.tfs.core.clients.sharepoint.WSSDocumentLibrary.java

@Override
public int compareTo(final Object compare) {
    if (!(compare instanceof WSSDocumentLibrary)) {
        throw new ClassCastException(MessageFormat.format(
                "A WssDocumentLibrary to compare against was expected, class passed was {0}", //$NON-NLS-1$
                compare.getClass().getName()));
    }//  w w  w . j  ava  2s .  co  m

    final WSSDocumentLibrary anotherLib = (WSSDocumentLibrary) compare;

    return getLabel().compareTo(anotherLib.getLabel());
}