List of usage examples for java.lang ClassCastException ClassCastException
public ClassCastException(String s)
ClassCastException
with the specified detail message. From source file:com.androzic.route.RouteDetails.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 va 2 s. c o m fragmentHolderCallback = (FragmentHolder) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement FragmentHolder"); } try { routeActionsCallback = (OnRouteActionListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnRouteActionListener"); } try { waypointActionsCallback = (OnWaypointActionListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnWaypointActionListener"); } }
From source file:fr.simon.marquis.preferencesmanager.ui.RestoreDialogFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {/*w w w. j a v a 2s. c o m*/ listener = (OnRestoreFragmentInteractionListener) activity; } catch (ClassCastException e) { throw new ClassCastException( activity.toString() + " must implement OnRestoreFragmentInteractionListener"); } }
From source file:com.ae.apps.messagecounter.fragments.MessageListFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {/* w w w .j a va2 s. c om*/ // Register for a callback when the data is ready mReader = (MessageDataReader) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnCheckStatusListener"); } }
From source file:ConversionUtil.java
/** * Attempts to convert an object to Comparable instance. */// w w w . j a va 2 s . com public static String toString(Object object) { if (object == null) { return null; } else if (object instanceof String) { return (String) object; } else if (object instanceof StringBuffer) { return object.toString(); } else if (object instanceof char[]) { return new String((char[]) object); } else { throw new ClassCastException("Invalid class for String conversion:" + object.getClass().getName()); } }
From source file:com.github.haixing_hu.bean.DefaultProperty.java
@SuppressWarnings("unchecked") @Override//from w w w. j ava2s . c om public final void setRawValue(@Nullable final Object value) { switch (descriptor.getKind()) { case INDEXED: if (value == null) { throw new NullPointerException("value is null."); } if (!(value instanceof ArrayList)) { throw new ClassCastException("The value of an indexed property must be a java.util.ArrayList."); } // FIXME: check the generic argument type of the ArrayList setIndexedValue((ArrayList<Object>) value); return; case MAPPED: if (value == null) { throw new NullPointerException("value is null."); } if (!(value instanceof HashMap)) { throw new ClassCastException("The value of a mapped property must be a java.util.HashMap."); } // FIXME: check the generic argument type of the HashMap setMappedValue((HashMap<String, Object>) value); return; case SIMPLE: default: this.value = value; return; } }
From source file:org.openhab.habdroid.ui.OpenHABDiscoveryFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); Log.d(TAG, "onAttach()"); try {/*from w w w . j av a 2s . c o m*/ mActivity = (OpenHABMainActivity) activity; mAsyncHttpClient = mActivity.getAsyncHttpClient(); mActivity.setTitle(R.string.app_discovery); } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must be OpenHABMainActivity"); } }
From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.FileGraphSetup.java
@Override public void contextInitialized(ServletContextEvent sce) { boolean aboxChanged = false; // indicates whether any ABox file graph model has changed boolean tboxChanged = false; // indicates whether any TBox file graph model has changed ServletContext ctx = sce.getServletContext(); try {//from w w w .j av a 2 s. c o m OntDocumentManager.getInstance().setProcessImports(true); Dataset dataset = ModelAccess.on(ctx).getDataset(); RDFService rdfService = ModelAccess.on(ctx).getRDFService(CONTENT); // ABox files Set<Path> paths = getFilegraphPaths(ctx, RDF, ABOX, FILEGRAPH); cleanupDB(dataset, pathsToURIs(paths, ABOX), ABOX); // Just update the ABox filegraphs in the DB; don't attach them to a base model. aboxChanged = readGraphs(paths, rdfService, ABOX, /* aboxBaseModel */ null); // TBox files paths = getFilegraphPaths(ctx, RDF, TBOX, FILEGRAPH); cleanupDB(dataset, pathsToURIs(paths, TBOX), TBOX); OntModel tboxBaseModel = ModelAccess.on(ctx).getOntModel(ModelNames.TBOX_ASSERTIONS); tboxChanged = readGraphs(paths, rdfService, TBOX, tboxBaseModel); } catch (ClassCastException cce) { String errMsg = "Unable to cast servlet context attribute to the appropriate type " + cce.getLocalizedMessage(); log.error(errMsg); throw new ClassCastException(errMsg); } catch (Throwable t) { log.error(t, t); } finally { OntDocumentManager.getInstance().setProcessImports(false); } if ((aboxChanged || tboxChanged) && !isUpdateRequired(ctx)) { log.info("a full recompute of the Abox will be performed because" + " the filegraph abox(s) and/or tbox(s) have changed or are being read for the first time."); SimpleReasonerSetup.setRecomputeRequired(ctx, SimpleReasonerSetup.RecomputeMode.BACKGROUND); } }
From source file:com.akhbulatov.wordkeeper.ui.fragment.CategoryListFragment.java
@SuppressWarnings("deprecation") @Override//from www. ja v a2 s . co m public void onAttach(Activity activity) { super.onAttach(activity); try { mListener = (FabAddWordListener) activity; } catch (ClassCastException e) { throw new ClassCastException( activity.toString() + " must implement " + FabAddWordListener.class.getName()); } }
From source file:at.ac.tuwien.detlef.fragments.EpisodeListFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {//w w w .j ava 2s .c o m listener = (OnEpisodeSelectedListener) activity; } catch (ClassCastException e) { throw new ClassCastException(String.format("%s must implement %s", activity.toString(), OnEpisodeSelectedListener.class.getName())); } }
From source file:com.buffalokiwi.aerodrome.jet.Utils.java
/** * Convert a json array to a list of integers. * if arr is null, then an empty List<Integer> instance is returned. * /*from w w w. j a v a 2s . 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 an integer */ public static List<Integer> jsonArrayToIntList(final JsonArray arr) { final List<Integer> out = new ArrayList<>(); if (arr == null) return out; for (int i = 0; i < arr.size(); i++) { final Integer j; try { j = arr.getInt(i); } catch (ClassCastException e) { APILog.error(LOG, e, arr.get(i)); continue; } if (j == null) { throw new ClassCastException( "Element at position " + String.valueOf(i) + " is null - Integer required"); } out.add(j); } return out; }