List of usage examples for java.lang ClassCastException ClassCastException
public ClassCastException(String s)
ClassCastException
with the specified detail message. From source file:augsburg.se.alltagsguide.start.LocationFragment.java
@Override public void onAttach(Context context) { super.onAttach(context); try {//w w w . j a v a 2 s . co m mListener = (OnLocationFragmentInteractionListener) context; } catch (ClassCastException e) { throw new ClassCastException(context.toString() + " must implement OnFragmentInteractionListener"); } }
From source file:com.royclarkson.springagram.GalleryListFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {/*from w w w . j av a 2 s.com*/ galleryListFragmentListener = (GalleryListFragmentListener) activity; } catch (ClassCastException e) { throw new ClassCastException( activity.toString() + " must implement OnGalleryFragmentInteractionListener"); } }
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}.// w w w . j a v a 2s. c o m * * @since 0.1.0 * @version 0.1.0 * * @param <T> The type of the casting class * @param c The class type to cast to * @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 */ default public <T> T as(Class<T> c) { Validate.notNull(c, "Cannot cast to null"); Validate.isTrue(Primitives.unwrap(c) != void.class, "Cannot cast to a void type"); boolean primitive = Primitives.isWrapperType(c) || Primitives.isWrapperType(Primitives.wrap(c)); Object o = this.get(); if (primitive) { T back; if (o == null) { return Reflections.defaultPrimitiveValue(c); } else { back = Primitives.wrap(c).cast(o); } return back; } if (o == null) { return null; } if (c == String.class) { return (T) String.valueOf(o); } if (c.isInstance(o)) { return c.cast(o); } if (c.isInstance(this.getDefault())) { return c.cast(this.getDefault()); } throw new ClassCastException("Unable to cast config value"); }
From source file:com.learnit.LearnIt.async_tasks.GetTranslationsWebTask.java
@Override protected void onPostExecute(Pair<String, List<String>> articleTranslationsListPair) { super.onPostExecute(articleTranslationsListPair); if (articleTranslationsListPair == null) { _taskActionCallback.onFail();// w w w .ja va 2 s. c o m return; } if (_taskActionCallback instanceof IWorkerEventListenerTranslations) { ((IWorkerEventListenerTranslations) _taskActionCallback) .onSuccessTranslations(articleTranslationsListPair); } else { throw new ClassCastException(_taskActionCallback.getClass().getSimpleName() + " must implement " + IWorkerEventListenerTranslations.class.getSimpleName()); } }
From source file:com.anton.gavel.PersonalInfoDialogFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); // Verify that the host activity implements the callback interface try {//from w w w .j a v a 2 s .c om // Instantiate the NoticeDialogListener so we can send events to the host mListener = (PersonalInfoListener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception throw new ClassCastException(activity.toString() + " must implement PersonalInfoListener"); } }
From source file:com.conferenceengineer.android.iosched.ui.TrackInfoHelperFragment.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 ww.j a v a 2 s . c o m*/ mCallbacks = (Callbacks) activity; if (mTrackId != null) { mHandler.post(new Runnable() { @Override public void run() { mCallbacks.onTrackInfoAvailable(mTrackId, mInfo); } }); } }
From source file:com.tdispatch.passenger.fragment.OAuthFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {/*from w w w .j ava2 s . c om*/ mHostActivity = (OAuthHostInterface) activity; } catch (ClassCastException e) { throw new ClassCastException("Host Activity needs to implement OAuthHostInterface"); } }
From source file:com.androzic.track.TrackList.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 ava2 s. c o m*/ trackActionsCallback = (OnTrackActionListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnTrackActionListener"); } }
From source file:augsburg.se.alltagsguide.start.LanguageFragment.java
@Override public void onAttach(Context context) { super.onAttach(context); try {//ww w .ja v a 2 s .co m mListener = (OnLanguageFragmentInteractionListener) context; } catch (ClassCastException e) { throw new ClassCastException( context.toString() + " must implement OnLanguageFragmentInteractionListener"); } }
From source file:org.anhonesteffort.flock.SubscriptionGoogleFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); if (activity instanceof ManageSubscriptionActivity) this.subscriptionActivity = (ManageSubscriptionActivity) activity; else/* w ww .ja v a 2 s. c om*/ throw new ClassCastException(activity.toString() + " not what I expected D: !"); }