Example usage for java.lang ClassCastException ClassCastException

List of usage examples for java.lang ClassCastException ClassCastException

Introduction

In this page you can find the example usage for java.lang ClassCastException ClassCastException.

Prototype

public ClassCastException(String s) 

Source Link

Document

Constructs a ClassCastException with the specified detail message.

Usage

From source file:com.ericbarnhill.arrayMath.MathArrayFloat1D.java

protected MathArrayFloat1D subtractC(Complex g) {
    throw new ClassCastException("Cannot subtract Complex number to double array");
}

From source file:com.ericbarnhill.arrayMath.MathArrayFloat2D.java

protected MathArrayFloat2D subtractC(Complex g) {
    throw new ClassCastException("Cannot subtract Complex number to double array");
}

From source file:com.ericbarnhill.arrayMath.MathArrayFloat3D.java

protected MathArrayFloat3D subtractC(Complex g) {
    throw new ClassCastException("Cannot subtract Complex number to double array");
}

From source file:com.graphaware.common.util.PropertyContainerUtils.java

private static float getFloat(String pc, String key, Object value) {
    if (value instanceof Byte) {
        return ((Byte) value).floatValue();
    }//from  w ww.j  a  va2s.  c  o m

    if (value instanceof Double) {
        return ((Double) value).floatValue();
    }

    if (value instanceof Integer) {
        return ((Integer) value).floatValue();
    }

    if (value instanceof Long) {
        return ((Long) value).floatValue();
    }

    if (value instanceof Float) {
        return (Float) value;
    }

    throw new ClassCastException(value + " is not a number! (" + pc + ", key=" + key + ")");
}

From source file:com.anysoftkeyboard.ui.settings.wordseditor.UserDictionaryEditorFragment.java

private void fillWordsList() {
    Log.d(TAG, "Selected locale is " + mSelectedLocale);
    new UserWordsEditorAsyncTask(this) {
        private EditableDictionary mNewDictionary;
        private List<UserWordsListAdapter.Word> mWordsList;

        @Override//from   w w  w .ja v  a 2s .co m
        protected void onPreExecute() {
            super.onPreExecute();
            // all the code below can be safely (and must) be called in the
            // UI thread.
            mNewDictionary = getEditableDictionary(mSelectedLocale);
            if (mNewDictionary != mCurrentDictionary && mCurrentDictionary != null && mCursor != null) {
                mCurrentDictionary.close();
            }
        }

        @Override
        protected Void doAsyncTask(Void[] params) throws Exception {
            mCurrentDictionary = mNewDictionary;
            mCurrentDictionary.loadDictionary();
            mCursor = mCurrentDictionary.getWordsCursor();
            Cursor cursor = mCursor.getCursor();
            mWordsList = new ArrayList<>(mCursor.getCursor().getCount());
            cursor.moveToFirst();
            while (!cursor.isAfterLast()) {
                UserWordsListAdapter.Word word = new UserWordsListAdapter.Word(mCursor.getCurrentWord(),
                        mCursor.getCurrentWordFrequency());
                mWordsList.add(word);
                cursor.moveToNext();
            }
            //now, sorting the word list alphabetically
            Collections.sort(mWordsList, msWordsComparator);
            return null;
        }

        protected void applyResults(Void result, Exception backgroundException) {
            ListAdapter adapter = getWordsListAdapter(mWordsList);
            //AbsListView introduced the setAdapter method in API11, so I'm required to check the instance type
            if (mWordsListView instanceof ListView) {
                //this is NOT a redundant cast!
                ((ListView) mWordsListView).setAdapter(adapter);
            } else if (mWordsListView instanceof GridView) {
                //this is NOT a redundant cast!
                ((GridView) mWordsListView).setAdapter(adapter);
            } else {
                throw new ClassCastException("Unknown mWordsListView type " + mWordsListView.getClass());
            }
        }
    }.execute();
}

From source file:com.github.chenxiaolong.dualbootpatcher.switcher.InAppFlashingFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (savedInstanceState != null) {
        ArrayList<MbtoolAction> savedActions = savedInstanceState.getParcelableArrayList(EXTRA_PENDING_ACTIONS);
        mPendingActions.addAll(savedActions);
    }/*from www .j a v a  2 s  . co m*/

    mProgressBar = (ProgressBar) getActivity().findViewById(R.id.card_list_loading);
    RecyclerView cardListView = (RecyclerView) getActivity().findViewById(R.id.card_list);

    mAdapter = new PendingActionCardAdapter(getActivity(), mPendingActions);
    cardListView.setHasFixedSize(true);
    cardListView.setAdapter(mAdapter);

    DragSwipeItemTouchCallback itemTouchCallback = new DragSwipeItemTouchCallback(this);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchCallback);
    itemTouchHelper.attachToRecyclerView(cardListView);

    LinearLayoutManager llm = new LinearLayoutManager(getActivity());
    llm.setOrientation(LinearLayoutManager.VERTICAL);
    cardListView.setLayoutManager(llm);

    final FloatingActionMenu fabMenu = (FloatingActionMenu) getActivity().findViewById(R.id.fab_add_item_menu);
    FloatingActionButton fabAddPatchedFile = (FloatingActionButton) getActivity()
            .findViewById(R.id.fab_add_patched_file);
    FloatingActionButton fabAddBackup = (FloatingActionButton) getActivity().findViewById(R.id.fab_add_backup);

    fabAddPatchedFile.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            addPatchedFile();
            fabMenu.close(true);
        }
    });
    fabAddBackup.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            addBackup();
            fabMenu.close(true);
        }
    });

    if (savedInstanceState != null) {
        mSelectedUri = savedInstanceState.getParcelable(EXTRA_SELECTED_URI);
        mSelectedUriFileName = savedInstanceState.getString(EXTRA_SELECTED_URI_FILE_NAME);
        mSelectedBackupDirUri = savedInstanceState.getParcelable(EXTRA_SELECTED_BACKUP_DIR_URI);
        mSelectedBackupName = savedInstanceState.getString(EXTRA_SELECTED_BACKUP_NAME);
        mSelectedBackupTargets = savedInstanceState.getStringArray(EXTRA_SELECTED_BACKUP_TARGETS);
        mSelectedRomId = savedInstanceState.getString(EXTRA_SELECTED_ROM_ID);
        mZipRomId = savedInstanceState.getString(EXTRA_ZIP_ROM_ID);
        mAddType = (Type) savedInstanceState.getSerializable(EXTRA_ADD_TYPE);
        mTaskIdVerifyZip = savedInstanceState.getInt(EXTRA_TASK_ID_VERIFY_ZIP);
        mQueryingMetadata = savedInstanceState.getBoolean(EXTRA_QUERYING_METADATA);
    }

    try {
        mActivityCallback = (OnReadyStateChangedListener) getActivity();
    } catch (ClassCastException e) {
        throw new ClassCastException(getActivity().toString() + " must implement OnReadyStateChangedListener");
    }

    mActivityCallback.onReady(!mPendingActions.isEmpty());

    mPrefs = getActivity().getSharedPreferences("settings", 0);

    if (savedInstanceState == null) {
        boolean shouldShow = mPrefs.getBoolean(PREF_SHOW_FIRST_USE_DIALOG, true);
        if (shouldShow) {
            FirstUseDialog d = FirstUseDialog.newInstance(this, R.string.in_app_flashing_title,
                    R.string.in_app_flashing_dialog_first_use);
            d.show(getFragmentManager(), CONFIRM_DIALOG_FIRST_USE);
        }
    }

    getActivity().getLoaderManager().initLoader(0, null, this);
}

From source file:eu.planets_project.tb.impl.model.ontology.OntologyPropertyImpl.java

/**
 * converts RDFIndividual (super class) to OWLIndividual (sub class) if possible
 * @param indiv/*  w  ww .  j a  v  a2s. c om*/
 * @return
 */
private OWLIndividual convertRDFIndividual(RDFIndividual indiv) throws ClassCastException {
    try {
        return (OWLIndividual) indiv;
    } catch (ClassCastException e) {
        throw new ClassCastException("RDFIndividual " + indiv.getLocalName() + " not of type OWLIndividual");
    }
}

From source file:org.jfree.data.xy.DefaultWindDataset.java

/**
 * Compares this item to another object.
 *
 * @param object  the other object.// w  ww.  ja  v  a 2 s.c  o m
 *
 * @return An int that indicates the relative comparison.
 */
@Override
public int compareTo(Object object) {
    if (object instanceof WindDataItem) {
        WindDataItem item = (WindDataItem) object;
        if (this.x.doubleValue() > item.x.doubleValue()) {
            return 1;
        } else if (this.x.equals(item.x)) {
            return 0;
        } else {
            return -1;
        }
    } else {
        throw new ClassCastException("WindDataItem.compareTo(error)");
    }
}

From source file:de.elanev.studip.android.app.backend.net.oauth.SignInFragment.java

@Override
public void onAttach(Activity activity) {
    Log.i(TAG, "onAttach Called!");
    super.onAttach(activity);
    try {//  w  ww.ja  v  a2  s. co m
        mCallbacks = (OnRequestTokenReceived) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + "must implement OnWebViewAuthListener");
    }
}

From source file:com.deliciousdroid.fragment.AddBookmarkFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {/*from   ww w . j av a2  s .co  m*/
        bookmarkSaveListener = (OnBookmarkSaveListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement OnBookmarkSaveListener");
    }
}