List of usage examples for java.lang ClassCastException ClassCastException
public ClassCastException(String s)
ClassCastException
with the specified detail message. From source file:com.ericbarnhill.arrayMath.MathArrayDouble1D.java
protected MathArrayDouble1D multiplyC(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); }
From source file:net.naijatek.myalumni.util.taglib.BuildDropdownTag.java
@SuppressWarnings("unchecked") private String renderOptions(List list) { StringBuffer sb = new StringBuffer(); boolean isString = true; if (list == null || list.size() == 0 || (list.size() == 1 && list.get(0) == null)) { return null; } else {//from w ww . ja va 2 s . c o m Object o = list.get(0); if (o instanceof String) { isString = true; } else if (o instanceof ValueLabelItem) { isString = false; } else { throw new ClassCastException( "Invalid list type passed to BuildDropdownTag.renderOptions; Must be List<String> or List<ValueLabelItem>"); } } for (int i = 0; i < list.size(); i++) { String value = null; String label = null; Object o = list.get(i); if (isString) { String s = (String) o; if (s != null) { value = s.trim(); label = s.trim(); } } else { ValueLabelItem item = (ValueLabelItem) o; if (item != null) { if (item.getItemValue() != null) { value = item.getItemValue().trim(); } if (item.getItemLabel() != null) { label = item.getItemLabel().trim(); } } } sb.append("<option value=\""); sb.append(value); sb.append("\""); if (getData() != null && !getData().equals("") && getData().trim().equalsIgnoreCase(value)) { sb.append(" selected"); } sb.append(">"); sb.append(label); sb.append("</option>"); } return sb.toString(); }
From source file:com.ericbarnhill.arrayMath.MathArrayDouble2D.java
protected MathArrayDouble2D multiplyC(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); }
From source file:ezbake.data.elastic.thrift.BaseFacetValue.java
@Override protected void checkType(_Fields setField, Object value) throws ClassCastException { switch (setField) { case FACET_FIELD: if (value instanceof String) { break; }//from ww w . j a v a 2 s. co m throw new ClassCastException("Was expecting value of type String for field 'facetField', but got " + value.getClass().getSimpleName()); case KEY_VALUE_FACET: if (value instanceof KeyValueFacet) { break; } throw new ClassCastException( "Was expecting value of type KeyValueFacet for field 'keyValueFacet', but got " + value.getClass().getSimpleName()); case KEY_VALUE_SCRIPT: if (value instanceof KeyValueScript) { break; } throw new ClassCastException( "Was expecting value of type KeyValueScript for field 'keyValueScript', but got " + value.getClass().getSimpleName()); default: throw new IllegalArgumentException("Unknown field id " + setField); } }
From source file:com.ericbarnhill.arrayMath.MathArrayDouble3D.java
protected MathArrayDouble3D multiplyC(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); }
From source file:com.ebaotech.salesplatform.commons.helper.SimpleSharedPreferences.java
@Override public String getString(String key, String defValue) throws ClassCastException { initiateSharedPreferences();// w w w .j a v a 2 s .co m try { return mSharedPreferences.getString(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.andryr.musicplayer.fragments.AlbumFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {/*from w w w . ja va2s .com*/ mActivity = (MainActivity) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnFragmentInteractionListener"); } }
From source file:com.impetus.kundera.proxy.cglib.CglibLazyInitializer.java
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (constructed) { String methodName = method.getName(); int params = args.length; if (params == 0) { if (isUninitialized() && method.equals(getIdentifierMethod)) { return getIdentifier(); }/*from w w w . ja va 2s .c o m*/ else if ("getKunderaLazyInitializer".equals(methodName)) { return this; } } Object target = getImplementation(); try { final Object returnValue; if (method.isAccessible()) { if (!method.getDeclaringClass().isInstance(target)) { throw new ClassCastException(target.getClass().getName()); } returnValue = method.invoke(target, args); } else { if (!method.isAccessible()) { method.setAccessible(true); } returnValue = method.invoke(target, args); } return returnValue == target ? proxy : returnValue; } catch (InvocationTargetException ite) { throw ite.getTargetException(); } } else { // while constructor is running throw new LazyInitializationException("unexpected case hit, method=" + method.getName()); } }
From source file:bluetoothchat.BluetoothChatFragment.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 .j av a2 s . c om*/ notifyActivityStickerStatusChange = (StepsFragment.OnStickerChange) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnHeadlineSelectedListener"); } }
From source file:com.chiorichan.util.ObjectUtil.java
public static Integer castToIntWithException(Object value) { if (value == null) return null; switch (value.getClass().getName()) { case "java.lang.Long": if ((long) value < Integer.MIN_VALUE || (long) value > Integer.MAX_VALUE) return (Integer) value; else/*from w w w . j a v a2 s. co m*/ return null; case "java.lang.String": return Integer.parseInt((String) value); case "java.lang.Integer": return (Integer) value; case "java.lang.Double": return (Integer) value; case "java.lang.Boolean": return ((boolean) value) ? 1 : 0; case "java.math.BigDecimal": return ((BigDecimal) value).setScale(0, BigDecimal.ROUND_HALF_UP).intValue(); default: throw new ClassCastException("Uncaught Convertion to Integer of Type: " + value.getClass().getName()); } }