List of usage examples for java.lang ClassCastException ClassCastException
public ClassCastException(String s)
ClassCastException
with the specified detail message. From source file:com.xhsoft.framework.common.utils.ClassUtil.java
/** * /*from w w w .ja v a 2s. com*/ * @param child * @param parent * @return * @throws ClassNotFoundException - Class * @author: lizj */ public static Class<?> getClass(String className, String parent) throws ClassNotFoundException { Class<?> childClass = ClassUtil.getClass(className); Class<?> parentClass = null; if (parent == null) { parentClass = Object.class; } else { parentClass = ClassUtil.getClass(parent); } if (!parentClass.isAssignableFrom(childClass)) { throw new ClassCastException(className + " class must be implement the " + parent + " interface."); } return childClass; }
From source file:ch.berta.fabio.popularmovies.presentation.ui.fragments.MovieDetailsBaseFragment.java
@Override public void onAttach(Context context) { super.onAttach(context); try {/*from w w w .j av a 2 s . c o m*/ mActivity = (FragmentInteractionListener) context; } catch (ClassCastException e) { throw new ClassCastException(context.toString() + " must implement FragmentInteractionListener"); } }
From source file:com.ericbarnhill.arrayMath.MathArrayDouble2D.java
protected MathArrayDouble2D addC(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); }
From source file:com.ericbarnhill.arrayMath.MathArrayDouble3D.java
protected MathArrayDouble3D addC(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); }
From source file:net.fizzl.redditengine.impl.MultiApi.java
/** * Return a list of multis belonging to the current user * //from w ww . ja v a 2 s . com * @return {@link MultiData}[] * @throws RedditEngineException */ public LabeledMulti[] getMyMultis() throws RedditEngineException { String url = String.format("%s%s", UrlUtils.BASE_URL, "/api/multi/mine"); LabeledMulti[] retval = null; try { SimpleHttpClient client = SimpleHttpClient.getInstance(); // Reponse may be an array of LabeledMultis or one MultiData in case of an error (403) // MultiData example: {"explanation": "please login to do that", "reason": "USER_REQUIRED"} InputStream in = client.get(url, null); // any error status will throw an exception Object response = GsonTemplate.fromInputStream(in, Object.class); in.close(); Gson gson = new Gson(); String json = gson.toJson(response); if (response instanceof List) { // reinterpret as LabeledMulti[] retval = gson.fromJson(json, LabeledMulti[].class); } else if (response instanceof Map) { // reinterpret as MultiData MultiData multiData = gson.fromJson(json, MultiData.class); // TODO how to return this? } else { throw new ClassCastException("don't know how to interpret response " + json); } } catch (ClientProtocolException e) { throw new RedditEngineException(e); } catch (IOException e) { throw new RedditEngineException(e); } catch (UnexpectedHttpResponseException e) { // TODO got a 403 but because of exception we don't know the exact error message throw new RedditEngineException(e); } return retval; }
From source file:com.ae.apps.messagecounter.fragments.MessageChartFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {// w w w .jav a 2s . co m mReader = (MessageDataReader) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnCheckStatusListener"); } }
From source file:com.androzic.waypoint.WaypointDetails.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 ww w .j a v a 2 s.co m fragmentHolderCallback = (FragmentHolder) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement FragmentHolder"); } try { waypointActionsCallback = (OnWaypointActionListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnWaypointActionListener"); } }
From source file:edu.wisc.commons.httpclient.HttpParamsBean.java
private <T> T getTypedParameter(String name, T defaultValue, Class<T> type, Function<Object, T> parser) { final Object value = delegate.getParameter(name); //If null return default value if (value == null) { return defaultValue; }// w w w. j a v a 2s.com //If already the right type just cast and return final Class<? extends Object> valueType = value.getClass(); if (type.isAssignableFrom(valueType)) { return type.cast(value); } //Try parsing the value to the desired type try { return parser.apply(value); } catch (Exception e) { final ClassCastException cce = new ClassCastException( "Cannot convert '" + value + "' of type " + valueType.getName() + " to " + type.getName()); cce.initCause(e); throw cce; } }
From source file:ch.ccapps.android.zeneggen.fragment.TabSectionListFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); Log.i("TabSectionListFragment", "- OnAttach -"); try {// ww w. jav a 2s . c o m tabSecInterface = ((CustomSectionListInterface<T>) activity).getTabSectionListInterface(); Log.i("TabSectionListFragment", " item Map is:" + itemMap); } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " You must implement CustomSectionListInterface"); } }
From source file:at.wada811.imageslider.ImageSliderFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); if (activity instanceof ImageSliderFragmentCallbackProvider == false) { throw new ClassCastException(activity.getLocalClassName() + " must implements " + ImageSliderFragmentCallbackProvider.class.getSimpleName()); }//from w w w. j a v a2s .c o m ImageSliderFragmentCallbackProvider provider = (ImageSliderFragmentCallbackProvider) activity; mCallback = provider.getImageSliderCallback(); }