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.blogspot.marioboehmer.thingibrowse.fragments.ThingResultListFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {/*w  ww.java 2s.c om*/
        onThingSelectedListener = (OnThingSelectedListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement OnThingSelectedListener");
    }
    try {
        onNetworkErrorListener = (OnNetworkErrorListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement OnNetworkErrorListener");
    }
    try {
        onNoResultsListener = (OnNoResultsListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement OnNoResultsListener");
    }
}

From source file:com.ariesmcrae.mymemories.ui.story.StoryListFragment.java

/**
 * @see android.support.v4.app.Fragment#onAttach(android.app.Activity)
 *//*from   ww w  .j  a  v a 2  s  .c  o  m*/
@Override
public void onAttach(Activity activity) {
    Log.d(LOG_TAG, "onAttach start");
    super.onAttach(activity);
    try {
        mOpener = (OnOpenWindowInterface) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(
                activity.toString() + " must implement OnOpenWindowListener" + e.getMessage());
    }
    Log.d(LOG_TAG, "onAttach end");
}

From source file:com.lovejoy777sarootool.rootool.fragments.BrowserFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);
    mObserverCache = FileObserverCache.getInstance();
    mActionController = new ActionModeController(activity);

    if (sHandler == null) {
        sHandler = new Handler(activity.getMainLooper());
    }//from   w ww.ja  va  2 s  .co  m

    try {
        mUpdatePathListener = (onUpdatePathListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement mUpdatePathListener");
    }
}

From source file:com.christophergs.mbientbasic.ModuleFragmentBase.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Activity owner = getActivity();//from w w  w .j ava 2s.com
    if (!(owner instanceof FragmentBus)) {
        throw new ClassCastException(String.format(Locale.US, "%s %s", owner.toString(),
                owner.getString(R.string.error_fragment_bus)));
    }

    fragBus = (FragmentBus) owner;
    owner.getApplicationContext().bindService(new Intent(owner, MetaWearBleService.class), this,
            Context.BIND_AUTO_CREATE);
}

From source file:com.couchbase.client.java.document.json.JsonObject.java

/**
 * Constructs a {@link JsonObject} from a {@link Map Map<String, ?>}.
 *
 * This is only possible if the given Map is well formed, that is it contains non null
 * keys, and all values are of a supported type.
 *
 * A null input Map or null key will lead to a {@link NullPointerException} being thrown.
 * If any unsupported value is present in the Map, an {@link IllegalArgumentException}
 * will be thrown.//from w  w  w . j  a va 2 s  . co m
 *
 * *Sub Maps and Lists*
 * If possible, Maps and Lists contained in mapData will be converted to JsonObject and
 * JsonArray respectively. However, same restrictions apply. Any non-convertible collection
 * will raise a {@link ClassCastException}. If the sub-conversion raises an exception (like an
 * IllegalArgumentException) then it is put as cause for the ClassCastException.
 *
 * @param mapData the Map to convert to a JsonObject
 * @return the resulting JsonObject
 * @throws IllegalArgumentException in case one or more unsupported values are present
 * @throws NullPointerException in case a null map is provided or if it contains a null key
 * @throws ClassCastException if map contains a sub-Map or sub-List not supported (see above)
 */
public static JsonObject from(Map<String, ?> mapData) {
    if (mapData == null) {
        throw new NullPointerException("Null input Map unsupported");
    } else if (mapData.isEmpty()) {
        return JsonObject.empty();
    }

    JsonObject result = new JsonObject(mapData.size());
    for (Map.Entry<String, ?> entry : mapData.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();

        if (value == JsonValue.NULL) {
            value = null;
        }

        if (key == null) {
            throw new NullPointerException("The key is not allowed to be null");
        } else if (value instanceof Map) {
            try {
                JsonObject sub = JsonObject.from((Map<String, ?>) value);
                result.put(key, sub);
            } catch (ClassCastException e) {
                throw e;
            } catch (Exception e) {
                ClassCastException c = new ClassCastException(
                        "Couldn't convert sub-Map " + key + " to JsonObject");
                c.initCause(e);
                throw c;
            }
        } else if (value instanceof List) {
            try {
                JsonArray sub = JsonArray.from((List<?>) value);
                result.put(key, sub);
            } catch (Exception e) {
                //no risk of a direct ClassCastException here
                ClassCastException c = new ClassCastException(
                        "Couldn't convert sub-List " + key + " to JsonArray");
                c.initCause(e);
                throw c;
            }
        } else if (!checkType(value)) {
            throw new IllegalArgumentException("Unsupported type for JsonObject: " + value.getClass());
        } else {
            result.put(key, value);
        }
    }
    return result;
}

From source file:com.baasbox.android.samples.aloa.activities.SendTargetFragment.java

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

From source file:com.tdispatch.passenger.fragment.BookingListFragment.java

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

    try {//from w  ww.  j  av a2s .c o  m
        mMapHostActivity = (MapHostInterface) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException("Host Activity needs to implement MapHostInterface");
    }
}

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

/**
 * Casts the wrapper to an array wrapper.
 *///from   www.j  av a  2s.  c  o  m
public JSONObj toObject() {
    if (this instanceof JSONObj) {
        return (JSONObj) this;
    }
    throw new ClassCastException("Not an object");
}

From source file:com.battlelancer.seriesguide.ui.dialogs.AddListDialogFragment.java

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

    try {//from   w w  w . ja  v a 2  s .  c  o m
        mListener = (OnListsChangedListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement OnListsChangedListener");
    }
}

From source file:com.anjalimacwan.fragment.NoteListFragment.java

@SuppressWarnings("deprecation")
@Override// w  w  w.  j  av  a2s.  c o  m
public void onAttach(Activity activity) {
    super.onAttach(activity);
    // Verify that the host activity implements the callback interface
    try {
        // 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");
    }
}