List of usage examples for java.lang ClassCastException ClassCastException
public ClassCastException(String s)
ClassCastException
with the specified detail message. From source file:com.github.cherimojava.data.mongo.entity.ParameterProperty.java
/** * validates the given value if it matches the defined constraints for this property. Throws * ConstraintViolationException if the value doesn't comply with the declared Constraints * * @param value property value to check for validity *//*from www . j a va2 s .c o m*/ public void validate(Object value) { if (value != null) { if (!type.isAssignableFrom(Primitives.wrap(value.getClass()))) { throw new ClassCastException(format("Can't cast from '%s' to '%s'", value.getClass().getCanonicalName(), type.getCanonicalName())); } } if (hasConstraints()) { Set<? extends ConstraintViolation<? extends Entity>> violations = validator .validateValue(declaringClass, pojoName, value, Entity.Special.class); if (!violations.isEmpty()) { StringBuilder msg = new StringBuilder().append("Found errors while validating property ") .append(declaringClass.getCanonicalName()).append("#").append(pojoName).append(":\n"); for (ConstraintViolation violation : violations) { msg.append("*").append(violation.getMessage()).append("\n"); } throw new ConstraintViolationException(msg.toString(), violations); } } }
From source file:com.ebaotech.salesplatform.commons.helper.SimpleSharedPreferences.java
@Override public Set<String> getStringSet(String key, Set<String> defValues) throws ClassCastException { initiateSharedPreferences();/*from w w w . ja v a 2 s .c om*/ final String jsonPref = getString(key, null); if (jsonPref == null) { return defValues; } final List<String> prefValues = new ArrayList<String>(); try { final JSONArray mJsonArray = new JSONObject(jsonPref).getJSONArray(key); for (int i = 0; i < mJsonArray.length(); i++) { prefValues.add(mJsonArray.getString(i)); } } catch (final JSONException e) { e.printStackTrace(); } try { return new HashSet<String>(prefValues); } 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"); } catch (final Exception e) { return defValues; } }
From source file:io.v.android.apps.syncslides.NavigationDrawerFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {// w w w. j av a 2 s .c om mCallbacks = (NavigationDrawerCallbacks) activity; } catch (ClassCastException e) { throw new ClassCastException("Activity must implement NavigationDrawerCallbacks."); } }
From source file:ezbake.data.elastic.thrift.ScriptValue.java
@Override protected void checkType(_Fields setField, Object value) throws ClassCastException { switch (setField) { case TEXT_VALUE: if (value instanceof String) { break; }// ww w.ja va 2s. co m throw new ClassCastException("Was expecting value of type String for field 'textValue', but got " + value.getClass().getSimpleName()); case INT_VALUE: if (value instanceof Integer) { break; } throw new ClassCastException("Was expecting value of type Integer for field 'intValue', but got " + value.getClass().getSimpleName()); case DOUBLE_VALUE: if (value instanceof Double) { break; } throw new ClassCastException("Was expecting value of type Double for field 'doubleValue', but got " + value.getClass().getSimpleName()); case LONG_VALUE: if (value instanceof Long) { break; } throw new ClassCastException("Was expecting value of type Long for field 'longValue', but got " + value.getClass().getSimpleName()); case BOOLEAN_VALUE: if (value instanceof Boolean) { break; } throw new ClassCastException("Was expecting value of type Boolean for field 'booleanValue', but got " + value.getClass().getSimpleName()); default: throw new IllegalArgumentException("Unknown field id " + setField); } }
From source file:com.owncloud.android.ui.fragment.FileDetailFragment.java
/** * {@inheritDoc}// w ww. j a v a2 s . 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 " + FileDetailFragment.ContainerActivity.class.getSimpleName()); } }
From source file:com.chiorichan.util.ObjectUtil.java
public static Long castToLongWithException(Object value) { if (value == null) return null; switch (value.getClass().getName()) { case "java.lang.Long": return (Long) value; case "java.lang.String": return Long.parseLong((String) value); case "java.lang.Integer": return (Long) value; case "java.lang.Double": return (Long) value; case "java.lang.Boolean": return ((boolean) value) ? 1L : 0L; case "java.math.BigDecimal": return ((BigDecimal) value).setScale(0, BigDecimal.ROUND_HALF_UP).longValue(); default:// www . j a va2s .com throw new ClassCastException("Uncaught Convertion to Long of Type: " + value.getClass().getName()); } }
From source file:cat.wuyingren.rorhelper.fragments.GameListFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); /*((MainActivity) activity).onSectionAttached( getArguments().getInt(ARG_SECTION_NUMBER));*/ // Verify that the host activity implements the callback interface try {//from ww w.j a va2s .c o m // Instantiate the NoticeDialogListener so we can send events to the host mListener = (GameListFragmentListener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception throw new ClassCastException(activity.toString() + " must implement ScenarioDialogListener"); } }
From source file:com.appnexus.opensdkapp.SettingsFragment.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 {//ww w . j av a 2 s . c om callback = (OnLoadAdClickedListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnLoadAdClickedListener"); } }
From source file:ca.frozen.curlingtv.activities.VideoFragment.java
@Override public void onAttach(Context context) { super.onAttach(context); try {/*ww w . j a va 2 s. c om*/ Activity activity = (Activity) context; fadeListener = (OnFadeListener) activity; } catch (ClassCastException e) { throw new ClassCastException(context.toString() + " must implement OnFadeListener"); } }
From source file:com.bq.robotic.robopad_plusplus.fragments.ScheduleRobotMovementsFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); // Check the listener is the correct one: the fragment activity container // implements that listener if (activity instanceof ScheduleRobotMovementsListener) { this.listener = (ScheduleRobotMovementsListener) activity; } else {/*from w w w .ja va 2 s . c om*/ throw new ClassCastException(activity.toString() + " must implement SelectBotListener"); } }