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:com.ericbarnhill.arrayMath.MathArrayFloat3D.java

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

From source file:com.cerema.cloud2.ui.fragment.SearchShareesFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {//from   ww w.  j ava  2  s  .  c om
        mListener = (ShareFragmentListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement OnFragmentInteractionListener");
    }
}

From source file:com.android.contacts.preference.DisplayOptionsPreferenceFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {/* ww  w.jav a2 s .c om*/
        mListener = (ProfileListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement ProfileListener");
    }
}

From source file:com.christophergs.mbientbasic.BothFragment.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   www.  ja  v a  2s  . c om*/
        mCallback = (OnFragTestListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement OnFragTestListener");
    }
}

From source file:fi.uta.infim.usaproxyreportgenerator.App.java

private static void setupDataProvider() {
    // A data provider class can be specified on the CLI.
    if (cli.hasOption("dataProvider")) {
        // Look for JAR files in the plugin dir
        File[] jars = PLUGINS_DIR.listFiles((FileFilter) new WildcardFileFilter("*.jar", IOCase.INSENSITIVE));
        URL[] jarUrls = new URL[jars.length];
        for (int i = 0; i < jars.length; ++i) {
            try {
                jarUrls[i] = jars[i].toURI().toURL();
            } catch (MalformedURLException e) {
                // Skip URL if not valid
                continue;
            }//  www .  j  a  v  a  2s  .c o  m
        }

        ClassLoader loader = URLClassLoader.newInstance(jarUrls, ClassLoader.getSystemClassLoader());
        String className = cli.getOptionValue("dataProvider");

        // Try to load the named class using a class loader. Fall back to
        // default if this fails.
        try {
            @SuppressWarnings("unchecked")
            Class<? extends DataProvider> cliOptionClass = (Class<? extends DataProvider>) Class
                    .forName(className, true, loader);
            if (!DataProvider.class.isAssignableFrom(cliOptionClass)) {
                throw new ClassCastException(cliOptionClass.getCanonicalName());
            }
            dataProviderClass = cliOptionClass;
        } catch (ClassNotFoundException e) {
            System.out.flush();
            System.err.println("Specified data provider class not found: " + e.getMessage());
            System.err.println("Falling back to default provider.");
        } catch (ClassCastException e) {
            System.out.flush();
            System.err.println("Specified data provider class is invalid: " + e.getMessage());
            System.err.println("Falling back to default provider.");
        }
        System.err.flush();
    }
}

From source file:com.app4am.app4am.LatestNewsListFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {//  w ww.  ja v a  2 s .c  om
        mListener = (SwipeRefreshFragmentInterface) getActivity();
    } catch (ClassCastException e) {
        throw new ClassCastException("Activity must implement SwipeRefreshFragmentInterface.");
    }
}

From source file:com.buffalokiwi.aerodrome.jet.Utils.java

/**
 * Convert a json array to a list of JsonObject instances.
 * if arr is null, then an empty List<JsonObject> instance is returned.
 * /* w w w.j  av a2s.c  o  m*/
 * This is more safe than JsonArray.getValuesAs() as this method
 * has built-in type checking and will throw a ClassCastException if 
 * the type is incorrect or null.
 * 
 * @param arr array
 * @return a list
 * @throws ClassCastException if any element in arr is not convertable to JsonObject
 */
public static List<JsonObject> jsonArrayToJsonObjectList(final JsonArray arr) {
    final List<JsonObject> out = new ArrayList<>();
    if (arr == null)
        return out;

    for (int i = 0; i < arr.size(); i++) {
        final JsonObject o = arr.getJsonObject(i);
        if (o == null) {
            throw new ClassCastException(
                    "Element at position " + String.valueOf(i) + " is null - JsonObject required");
        }

        out.add(o);
    }

    return out;
}

From source file:ca.ualberta.cs.cmput301w15t04team04project.FragmentEditItem2.java

/**
 * <p>This part of code is copied from:<br>
 * {@link http://stackoverflow.com/questions/13116104/best-practice-to-reference-the-parent-activity-of-a-fragment}
 * @since March 26//from  w  ww . j a  va 2  s . c o m
 */
@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {
        myActivity = (EditItemActivity) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must be EditItemActivity ");
    }
}

From source file:ezbake.data.elastic.thrift.DateField.java

@Override
protected void checkType(_Fields setField, Object value) throws ClassCastException {
    switch (setField) {
    case _FIELD:// w w  w .  j av a  2  s .co m
        if (value instanceof String) {
            break;
        }
        throw new ClassCastException("Was expecting value of type String for field '_field', but got "
                + value.getClass().getSimpleName());
    case KEY_VALUE_DATE_FIELD:
        if (value instanceof KeyValueFacet) {
            break;
        }
        throw new ClassCastException(
                "Was expecting value of type KeyValueFacet for field 'keyValueDateField', but got "
                        + value.getClass().getSimpleName());
    case KEY_VALUE_DATE_SCRIPT:
        if (value instanceof KeyValueDateScript) {
            break;
        }
        throw new ClassCastException(
                "Was expecting value of type KeyValueDateScript for field 'keyValueDateScript', but got "
                        + value.getClass().getSimpleName());
    default:
        throw new IllegalArgumentException("Unknown field id " + setField);
    }
}

From source file:com.conferenceengineer.android.iosched.ui.SessionsFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    if (!(activity instanceof Callbacks)) {
        throw new ClassCastException("Activity must implement fragment's callbacks.");
    }//from   w  w w .j  a  v  a2 s  .com

    mCallbacks = (Callbacks) activity;
    activity.getContentResolver().registerContentObserver(ScheduleContract.Sessions.CONTENT_URI, true,
            mObserver);

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity);
    sp.registerOnSharedPreferenceChangeListener(mPrefChangeListener);
}