List of usage examples for java.lang ClassCastException ClassCastException
public ClassCastException(String s)
ClassCastException
with the specified detail message. From source file:com.aikidonord.fragments.FragmentType.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 w ww .j a va2 s .c om mCallback = (OnTypeSelectedListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnLieuSelectedListener"); } }
From source file:br.liveo.searchliveo.SearchCardLiveo.java
public void build() { if (this.mSearchListener == null) { throw new ClassCastException(mContext.getString(R.string.warning_listener)); }/* w w w . j a va 2s. c o m*/ try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Resources.Theme theme = this.mContext.getTheme(); TypedArray typedArray = theme.obtainStyledAttributes(new int[] { android.R.attr.colorPrimaryDark }); setColorPrimaryDark(typedArray.getResourceId(0, 0)); } } catch (Exception e) { e.getStackTrace(); } }
From source file:com.ericbarnhill.arrayMath.MathArrayDouble1D.java
protected MathArrayDouble1D divide(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); }
From source file:com.ericbarnhill.arrayMath.MathArrayDouble2D.java
protected MathArrayDouble2D divide(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); }
From source file:com.ericbarnhill.arrayMath.MathArrayDouble3D.java
protected MathArrayDouble3D divide(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); }
From source file:org.openhab.habdroid.ui.OpenHABDiscoveryInboxFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); Log.d(TAG, "onAttach()"); try {// w ww .ja v a2s. c o m mActivity = (OpenHABMainActivity) activity; mAsyncHttpClient = mActivity.getAsyncHttpClient(); mActivity.setTitle(R.string.app_discoveryinbox); } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must be OpenHABMainActivity"); } }
From source file:com.scooter1556.sms.android.fragment.MediaElementFragment.java
@Override public void onAttach(Context context) { super.onAttach(context); try {/*from w w w . j a va 2s .c o m*/ mediaElementListener = (MediaElementListener) context; } catch (ClassCastException e) { throw new ClassCastException(context.toString() + " must implement MediaElementListener"); } }
From source file:com.helpshift.kvstore.SharedPreferencesImpl.java
@Override public long getLong(String key, long defValue) { String value = getValueByKey(key); if (value == null) { return defValue; } else {//from ww w . j a va 2 s. c om try { return Long.parseLong(getValueByKey(key)); } catch (NumberFormatException e) { throw new ClassCastException("can not cast to Long"); } } }
From source file:com.achow101.bitcointalkforum.fragments.MessagesFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {/* w ww . j a v a2 s .c o m*/ mListener = (OnPMInteraction) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnPMInteraction"); } }
From source file:net.sf.qooxdoo.rpc.RpcServlet.java
/** * Looks up an instance of a service and creates one if necessary. * * @param session the current session (for storing * instances). * @param serviceClassName the fully qualified name of the class * to instantiate. * @param name the name to use for the instance. * @param requiredType The type the service must have. May be * null. // w ww . j a va 2s .c om */ public synchronized Service getServiceInstance(HttpSession session, String serviceClassName, Object name, Class requiredType) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException { if (requiredType == null) { requiredType = Service.class; } String lookFor = serviceClassName; if (name != null) { lookFor += "/" + name; } Service inst = (Service) session.getAttribute(lookFor); if (inst == null) { Class clazz = Class.forName(serviceClassName); if (!requiredType.isAssignableFrom(clazz)) { throw new ClassCastException("The requested service class " + clazz.getName() + " is not from the required type " + requiredType.getName() + ""); } inst = (Service) clazz.newInstance(); Class[] paramTypes = new Class[1]; Object[] params = new Object[1]; paramTypes[0] = Environment.class; Method method = MethodUtils.getMatchingAccessibleMethod(clazz, "setWebcomponentEnvironment", paramTypes); if (method == null) { method = MethodUtils.getMatchingAccessibleMethod(clazz, "setQooxdooEnvironment", paramTypes); } if (method != null) { params[0] = new Environment(); method.invoke(inst, params); } if (name != null) { paramTypes[0] = String.class; method = MethodUtils.getMatchingAccessibleMethod(clazz, "setWebcomponentName", paramTypes); if (method != null) { params[0] = name; method.invoke(inst, params); } } session.setAttribute(lookFor, inst); // initialize the service properties ServletConfig servletConfig = getServletConfig(); Enumeration initParamNames = servletConfig.getInitParameterNames(); String initParamName; String initParamValue; int pos; String packageName; String propertyName; HashMap candidates = new HashMap(); while (initParamNames.hasMoreElements()) { initParamName = (String) initParamNames.nextElement(); pos = initParamName.lastIndexOf('.'); if (pos == -1) { packageName = ""; propertyName = initParamName; } else { packageName = initParamName.substring(0, pos); propertyName = initParamName.substring(pos + 1); } String candidateName; if (serviceClassName.startsWith(packageName)) { candidateName = (String) candidates.get(propertyName); if (candidateName == null) { candidates.put(propertyName, initParamName); } else if (candidateName.length() < initParamName.length()) { candidates.put(propertyName, initParamName); } } } Iterator candidatesIterator = candidates.keySet().iterator(); Class propertyType; while (candidatesIterator.hasNext()) { propertyName = (String) candidatesIterator.next(); initParamName = (String) candidates.get(propertyName); initParamValue = servletConfig.getInitParameter(initParamName); propertyType = PropertyUtils.getPropertyType(inst, propertyName); if (propertyType != null) { if (propertyType.getComponentType() == String.class) { PropertyUtils.setSimpleProperty(inst, propertyName, StringUtils.tokenize(initParamValue, ';')); } else { try { PropertyUtils.setSimpleProperty(inst, propertyName, ConvertUtils.convert(initParamValue, propertyType)); } catch (Exception e) { // try to instatiate a class of the supplied parameter //System.out.println("***** setting '" + propertyName + "' to an instance of '" + initParamValue + "'"); PropertyUtils.setSimpleProperty(inst, propertyName, getServiceInstance(session, initParamValue, null, null)); } } } else { //System.out.println("***** property '" + propertyName + "' not matched"); } } // tell the instance that we're done paramTypes = new Class[0]; method = MethodUtils.getMatchingAccessibleMethod(clazz, "webcomponentInit", paramTypes); if (method != null) { params = new Object[0]; method.invoke(inst, params); } } return inst; }