List of usage examples for java.lang ClassCastException ClassCastException
public ClassCastException(String s)
ClassCastException
with the specified detail message. From source file:com.codelanx.codelanxlib.config.Config.java
/** * Attempts to return the {@link Config} value as a casted type. If the * value cannot be casted it will attempt to return the default value. If * the default value is inappropriate for the class, the method will * throw a {@link ClassCastException}. This exception is also throwing if * the type used for the members contained within the collection are * incorrect/*from ww w . ja v a2 s . c om*/ * * @since 0.1.0 * @version 0.1.0 * * @param <T> The type of the casting class * @param <G> The type of the collection's contents * @param collection The collection type to cast to * @param type The generic bounding for the collection * @return A casted value, or {@code null} if unable to cast. If the passed * class parameter is of a primitive type or autoboxed primitive, * then a casted value of -1 is returned, or {@code false} for * booleans. If the passed class parameter is for {@link String}, * then {@link Object#toString()} is called on the value instead */ @SuppressWarnings("rawtypes") default public <G, T extends Collection<G>> T as(Class<? extends Collection> collection, Class<G> type) { Collection<G> col = this.as(collection); for (Object o : col) { if (!type.isInstance(o)) { throw new ClassCastException("Inappropriate generic type for collection"); } } return (T) col; }
From source file:com.nearnotes.NoteEdit.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {//from w w w.ja va2 s . c o m mCallback = (noteEditListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement noteEditListener"); } }
From source file:com.battlelancer.seriesguide.ui.PeopleFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {//from www . j a v a 2 s . c om mListener = (OnShowPersonListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnShowPersonListener"); } }
From source file:com.amazon.appstream.fireclient.ConnectDialogFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); mActivity = activity;/*from w w w . j a v a 2s. c om*/ // Verify that the host activity implements the callback interface try { // Instantiate the NoticeDialogListener so we can send events to the host mListener = (ConnectDialogListener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception throw new ClassCastException(activity.toString() + " must implement NoticeDialogListener"); } }
From source file:com.bt.aloha.call.state.InboundCallMessageFlowImpl.java
@Override public MediaNegotiationCommand processCallLegConnected(ImmutableDialogInfo eventDialogInfo, ImmutableDialogInfo otherDialogInfo, ReadOnlyCallInfo callInfo, boolean refreshOriginatedByCurrentCall, MediaDescription mediaDescription) { LOG.debug(String.format(//from w w w .j a v a2 s. c o m "Processing call leg connected event for call leg %s in call %s using sip flow %s, refresh originated by call is %s, media neg state is %s", eventDialogInfo.getId(), callInfo.getId(), this.getClass().getSimpleName(), refreshOriginatedByCurrentCall, callInfo.getMediaNegotiationState())); InboundCallInfo inboundCallInfo; if (callInfo instanceof InboundCallInfo) inboundCallInfo = (InboundCallInfo) callInfo; else throw new ClassCastException("Expected an Inbound call info for inbound sip message flow!"); MediaNegotiationCommand command = null; if (refreshOriginatedByCurrentCall) { command = super.processCallLegConnectedRefreshOriginatedByCurrentCall(eventDialogInfo, otherDialogInfo, callInfo, refreshOriginatedByCurrentCall, mediaDescription); } else if (inboundCallInfo.getMediaNegotiationState().equals(MediaNegotiationState.Pending)) { LOG.debug(String.format( "Call leg connected event for dialog %s with state %s NOT originated by current call", eventDialogInfo.getId(), callInfo.getCallLegConnectionState(eventDialogInfo.getId()))); ImmutableDialogInfo firstDialogInfo = eventDialogInfo.getId().equals(callInfo.getFirstDialogId()) ? eventDialogInfo : otherDialogInfo; ImmutableDialogInfo secondDialogInfo = eventDialogInfo.getId().equals(callInfo.getSecondDialogId()) ? eventDialogInfo : otherDialogInfo; LOG.debug(String.format( "Initiating media negotiation for call %s after connect - first leg is %s, second leg is %s", callInfo.getId(), firstDialogInfo.getId(), secondDialogInfo.getId())); return initializeCall(firstDialogInfo, secondDialogInfo, callInfo, null, true); } return command; }
From source file:com.androzic.MapList.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 {//w w w . j a v a 2 s . c o m mapActionsCallback = (OnMapActionListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnMapActionListener"); } }
From source file:com.acrylicgoat.bcponline.fragments.CPListFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); sherActivity = (FragmentActivity) activity; try {//from w ww . ja va 2 s. c o m ddgSelectedListener = (OnDDGSelectedListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnDDGSelectedListener"); } }
From source file:augsburg.se.alltagsguide.settings.PrefFragment.java
@Override public void onAttach(Context context) { super.onAttach(context); try {// www . j a va 2 s .co m mListener = (OnPreferenceListener) context; } catch (ClassCastException e) { throw new ClassCastException(context.toString() + " must implement OnPageFragmentInteractionListener"); } }
From source file:com.aikidonord.fragments.FragmentDate.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 {/*ww w . ja va 2 s. c o m*/ mCallback = (OnDateSelectedListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnLieuSelectedListener"); } }
From source file:com.aikidonord.fragments.FragmentLieu.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 w w w.j a va 2s . co m mCallback = (OnLieuSelectedListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnLieuSelectedListener"); } }