List of usage examples for java.lang ClassCastException ClassCastException
public ClassCastException(String s)
ClassCastException
with the specified detail message. From source file:com.davidmascharka.lips.SelectBuildingDialogFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); // Verify the host activity implements the callback interface try {//from w w w.jav a 2 s. co m // Instantiate the listener so we can send events to the host listener = (SelectBuildingDialogListener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface throw new ClassCastException(activity.toString() + " must implement SelectBuildingDialogListener"); } }
From source file:com.akhbulatov.wordkeeper.ui.dialog.WordEditorDialog.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {/*from w w w. ja v a 2s . co m*/ mListener = (WordEditorDialogListener) activity; } catch (ClassCastException e) { throw new ClassCastException( activity.toString() + " must implement " + WordEditorDialogListener.class.getName()); } }
From source file:com.delaroystudios.placepicker.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FragmentManager fm = getSupportFragmentManager(); PlacePickerFragment fragment = (PlacePickerFragment) fm.findFragmentByTag(FRAGTAG); if (fragment == null) { FragmentTransaction transaction = fm.beginTransaction(); fragment = new PlacePickerFragment(); transaction.add(fragment, FRAGTAG); transaction.commit();/*from w ww .j a va2 s . c o m*/ } // Use fragment as click listener for cards, but must implement correct interface if (!(fragment instanceof OnCardClickListener)) { throw new ClassCastException("PlacePickerFragment must " + "implement OnCardClickListener interface."); } OnCardClickListener clickListener = (OnCardClickListener) fm.findFragmentByTag(FRAGTAG); mRetentionFragment = (StreamRetentionFragment) fm.findFragmentByTag(RETENTION_TAG); if (mRetentionFragment == null) { mRetentionFragment = new StreamRetentionFragment(); fm.beginTransaction().add(mRetentionFragment, RETENTION_TAG).commit(); } else { // If the retention fragment already existed, we need to pull some state. // pull state out CardStreamState state = mRetentionFragment.getCardStream(); // dump it in CardStreamFragment. mCardStreamFragment = (CardStreamFragment) fm.findFragmentById(R.id.fragment_cardstream); mCardStreamFragment.restoreState(state, clickListener); } }
From source file:cl.smartcities.isci.transportinspector.dialogs.BusSelectionDialog.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); // Verify that the host activity implements the callback interface try {// w ww .j a v a2 s . c om // Instantiate the NoticeDialogListener so we can send events to the host listener = (BusSelectionAdapter.ListViewAdapterListener) 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.akhbulatov.wordkeeper.ui.dialog.CategoryEditorDialog.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try {/*from w ww.j av a2 s.c o m*/ mListener = (CategoryEditorDialogListener) getTargetFragment(); } catch (ClassCastException e) { throw new ClassCastException(getTargetFragment().toString() + " must implement " + CategoryEditorDialogListener.class.getName()); } Bundle args = getArguments(); if (args != null) { mTitleId = args.getInt(ARGUMENT_TITLE_ID); mPositiveTextId = args.getInt(ARGUMENT_POSITIVE_TEXT_ID); mNegativeTextId = args.getInt(ARGUMENT_NEGATIVE_TEXT_ID); } }
From source file:co.uk.aging.mabel.places.placepicker.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.start);/* ww w.j a va 2 s .c o m*/ FragmentManager fm = getSupportFragmentManager(); PlacePickerFragment fragment = (PlacePickerFragment) fm.findFragmentByTag(FRAGTAG); if (fragment == null) { FragmentTransaction transaction = fm.beginTransaction(); fragment = new PlacePickerFragment(); transaction.add(fragment, FRAGTAG); transaction.commit(); } // Use fragment as click listener for cards, but must implement correct interface if (!(fragment instanceof OnCardClickListener)) { throw new ClassCastException("PlacePickerFragment must " + "implement OnCardClickListener interface."); } OnCardClickListener clickListener = (OnCardClickListener) fm.findFragmentByTag(FRAGTAG); mRetentionFragment = (StreamRetentionFragment) fm.findFragmentByTag(RETENTION_TAG); if (mRetentionFragment == null) { mRetentionFragment = new StreamRetentionFragment(); fm.beginTransaction().add(mRetentionFragment, RETENTION_TAG).commit(); } else { // If the retention fragment already existed, we need to pull some state. // pull state out CardStreamState state = mRetentionFragment.getCardStream(); // dump it in CardStreamFragment. mCardStreamFragment = (CardStreamFragment) fm.findFragmentById(R.id.fragment_cardstream); mCardStreamFragment.restoreState(state, clickListener); } }
From source file:dtu.ds.warnme.app.dialog.ReportDialog.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {//w w w . j av a 2 s.com listener = (ReportDialogListener) activity; } catch (ClassCastException ex) { throw new ClassCastException(activity.toString() + " must implement ReportDialogListener"); } }
From source file:Utils.java
/** * Create a typesafe filter of an unchecked iterator. {@link Iterator#remove} * will work if it does in the unchecked iterator. * /*from w ww. j av a2 s.c o m*/ * @param rawIterator * an unchecked iterator * @param type * the desired enumeration type * @param strict * if false, elements which are not null but not assignable to the * requested type are omitted; if true, {@link ClassCastException} * may be thrown from an iterator operation * @return an iterator guaranteed to contain only objects of the requested * type (or null) */ public static <E> Iterator<E> checkedIteratorByFilter(Iterator rawIterator, final Class<E> type, final boolean strict) { return new CheckedIterator<E>(rawIterator) { protected boolean accept(Object o) { if (o == null) { return true; } else if (type.isInstance(o)) { return true; } else if (strict) { throw new ClassCastException(o + " was not a " + type.getName()); // NOI18N } else { return false; } } }; }
From source file:com.cerema.cloud2.ui.fragment.FileFragment.java
/** * {@inheritDoc}// w w w .ja va 2s. c o m */ @Override public void onAttach(Activity activity) { super.onAttach(activity); try { mContainerActivity = (ContainerActivity) activity; } catch (ClassCastException e) { throw new ClassCastException( activity.toString() + " must implement " + ContainerActivity.class.getSimpleName()); } }
From source file:com.github.xbn.array.helper.ArrayHelperBaseComposer.java
@SuppressWarnings("unchecked") public Iterator<E> getIterator(Object obj_thatIsArray, String array_name) { try {/*ww w . j a v a 2s. c om*/ return (Iterator<E>) (new ObjectArrayIterator(obj_thatIsArray)); } catch (ClassCastException ccx) { throw new ClassCastException("obj_thatIsArray is not an E[]: obj_thatIsArray.getClass().getName()=\"" + obj_thatIsArray.getClass().getName() + "\". // Original exception: " + ccx); } }