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:org.apache.syncope.core.persistence.beans.user.SyncopeUser.java

@Override
public <T extends AbstractAttr> boolean removeAttribute(final T attribute) {
    if (!(attribute instanceof UAttr)) {
        throw new ClassCastException(
                "attribute is expected to be typed UAttr: " + attribute.getClass().getName());
    }/*  ww  w.  j a va  2 s.  co  m*/

    return attributes.remove((UAttr) attribute);
}

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

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

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

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

    if (savedInstanceState != null) {
        ArrayList<PendingAction> savedActions = savedInstanceState
                .getParcelableArrayList(EXTRA_PENDING_ACTIONS);
        mPendingActions.addAll(savedActions);
    }//from   ww w. j a  va2s .  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);

    AddFloatingActionButton fabFlashZip = (AddFloatingActionButton) getActivity()
            .findViewById(R.id.fab_add_zip);
    fabFlashZip.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            // Show file chooser
            Intent intent = FileUtils.getFileOpenIntent(getActivity());
            startActivityForResult(intent, ACTIVITY_REQUEST_FILE);
        }
    });

    if (savedInstanceState != null) {
        mSelectedFile = savedInstanceState.getString(EXTRA_SELECTED_FILE);
        mSelectedRomId = savedInstanceState.getString(EXTRA_SELECTED_ROM_ID);
        mZipRomId = savedInstanceState.getString(EXTRA_ZIP_ROM_ID);
        mTaskIdVerifyZip = savedInstanceState.getInt(EXTRA_TASK_ID_VERIFY_ZIP);
    }

    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.zip_flashing_title,
                    R.string.zip_flashing_dialog_first_use);
            d.show(getFragmentManager(), CONFIRM_DIALOG_FIRST_USE);
        }
    }

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

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

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

From source file:com.android.contacts.ContactSaveService.java

public static void registerListener(Listener listener) {
    if (!(listener instanceof Activity)) {
        throw new ClassCastException("Only activities can be registered to" + " receive callback from "
                + ContactSaveService.class.getName());
    }//from w  w  w. j  av a2  s .c om
    sListeners.add(0, listener);
}

From source file:com.vilt.minium.impl.BaseWebElementsImpl.java

@SuppressWarnings("unchecked")
@Override/* www.j  av a 2s.com*/
public <WE extends WebElements> WE as(Class<WE> clazz) {
    if (!clazz.isAssignableFrom(this.getClass())) {
        throw new ClassCastException(format(
                "WebElements does not implement %s. Ensure that the class is passed as an extension interface in DefaultWebElementsDriver constructor",
                clazz.getName()));
    }
    return (WE) this;
}

From source file:org.jasig.cas.support.oauth.token.registry.JpaTokenRegistry.java

/**
 * Retrieve the token implementation class of the clazz specified.
 *
 * @param clazz The assignable form of the implementation class.
 * @param <T> the generic token type to return that extends {@link Token}
 * @return the token implementation class.
 * @throws ClassCastException the class cast exception.
 *///  w  w w. j  av a2s.  c om
@SuppressWarnings("unchecked")
private <T extends Token> Class<T> getClassImplementation(final Class<T> clazz) throws ClassCastException {
    if (AuthorizationCode.class.isAssignableFrom(clazz)) {
        return (Class<T>) AuthorizationCodeImpl.class;
    } else if (RefreshToken.class.isAssignableFrom(clazz)) {
        return (Class<T>) RefreshTokenImpl.class;
    } else if (AccessToken.class.isAssignableFrom(clazz)) {
        return (Class<T>) AccessTokenImpl.class;
    }

    throw new ClassCastException("Could not cast " + clazz + " to a suitable token implementation class");
}

From source file:com.ebaotech.salesplatform.commons.helper.SimpleSharedPreferences.java

@Override
public long getLong(String key, long defValue) throws ClassCastException {
    initiateSharedPreferences();//from ww  w  . j  ava  2s  .co m
    try {
        return mSharedPreferences.getLong(key, defValue);
    } catch (final ClassCastException e) {
        final String returnType = new Object() {
        }.getClass().getEnclosingMethod().getReturnType().toString();
        throw new ClassCastException("\n ======================================== \nClassCastException : " + key
                + "'s value is not a " + returnType + " \n ======================================== \n");
    }
}

From source file:com.chiorichan.util.ObjectUtil.java

public static String castToStringWithException(Object value) {
    if (value == null)
        return null;

    switch (value.getClass().getName()) {
    case "java.lang.Long":
        return Long.toString((long) value);
    case "java.lang.String":
        return (String) value;
    case "java.lang.Integer":
        return Integer.toString((int) value);
    case "java.lang.Double":
        return Double.toString((double) value);
    case "java.lang.Boolean":
        return ((boolean) value) ? "true" : "false";
    case "java.math.BigDecimal":
        return ((BigDecimal) value).toString();
    case "java.util.Map":
        return value.toString();
    case "java.util.List":
        return value.toString();
    default://  w  ww .java 2s . co m
        throw new ClassCastException("Uncaught Convertion to String of Type: " + value.getClass().getName());
    }
}