Example usage for java.lang ClassCastException toString

List of usage examples for java.lang ClassCastException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.deange.textfaker.utils.FragmentUtils.java

/**
 * Find a Fragment within a given activity, and recaptures the reference
 *
 * @param outFragment the fragment to find
 * @param manager     the support fragment manager of the activity
 * @param fragmentTag the tag associated with the fragment
 *//*from w w  w . jav a2s.  c o  m*/
public static void findFragment(Fragment outFragment, final FragmentManager manager, final String fragmentTag) {
    if (outFragment == null) {
        try {
            outFragment = manager.findFragmentByTag(fragmentTag);
        } catch (final ClassCastException e) {
            Log.e(TAG, "Error attempting to find Fragment with tag: \"" + fragmentTag + "\": " + e.toString());
        }
    }
}

From source file:com.deange.textfaker.utils.FragmentUtils.java

/**
 * Finds a PatchedDialogFragment with a given callback, and sets it if non-null.
 * Should be used on any orientation changes to recapture references to dialog fragments
 *
 * @param outDialog the patcheddialogfragment to find
 * @param manager   the support fragment manager of the activity
 * @param callback  the patcheddialogfragment's callback object
 * @param dialogTag the tag associated with the dialog
 *///w  w  w  . ja va 2 s  .c om
@SuppressWarnings("unchecked")
public static void findDialogFragment(PatchedDialogFragment outDialog, final FragmentManager manager,
        final Object callback, final String dialogTag) {
    if (outDialog == null) {
        try {
            outDialog = (PatchedDialogFragment) manager.findFragmentByTag(dialogTag);
            if (outDialog != null) {
                outDialog.setCallback(callback);
            }
        } catch (final ClassCastException e) {
            Log.e(TAG,
                    "Error attempting to find DialogFragment with tag: \"" + dialogTag + "\": " + e.toString());
        }
    }
}

From source file:de.cbb.mplayer.util.ReflectionHelper.java

public static Method getter(Object source, String field) {
    Method getter = null;//  w ww  . j  av  a 2  s  .  c o  m
    try {
        getter = source.getClass().getDeclaredMethod(
                ReflectionHelper.getterName(field, ReflectionHelper.getFieldType(source, field)));
    } catch (java.lang.ClassCastException ex) {
        log.warn("getter: No cast available for: " + field);
    } catch (Exception ex) {
        log.warn(ex.toString());
    }
    return getter;
}

From source file:de.cbb.mplayer.util.ReflectionHelper.java

private static Object unmappedValueOfGetter(Object source, String field) {
    Object value = null;//  w  w  w . ja va2s.c  o m
    Method getter = getter(source, field);
    try {
        value = getter.invoke(source, null);
    } catch (java.lang.ClassCastException ex) {
        log.warn("valueOfGetter: No cast available for: " + field);
    } catch (Exception ex) {
        log.warn(ex.toString());
    }
    return value;
}

From source file:org.opendatakit.common.android.utilities.ODKCursorUtils.java

/**
 * Return the data stored in the cursor at the given index and given position
 * (ie the given row which the cursor is currently on) as null OR whatever
 * data type it is.//from  w  ww .ja v  a2s .  c o m
 * <p>
 * This does not actually convert data types from one type to the other.
 * Instead, it safely preserves null values and returns boxed data values. If
 * you specify ArrayList or HashMap, it JSON deserializes the value into one
 * of those.
 *
 * @param c
 * @param clazz
 * @param i
 * @return
 */
@SuppressWarnings("unchecked")
public static final <T> T getIndexAsType(Cursor c, Class<T> clazz, int i) {
    // If you add additional return types here be sure to modify the javadoc.
    try {
        if (i == -1)
            return null;
        if (c.isNull(i)) {
            return null;
        }
        if (clazz == Long.class) {
            Long l = c.getLong(i);
            return (T) l;
        } else if (clazz == Integer.class) {
            Integer l = c.getInt(i);
            return (T) l;
        } else if (clazz == Double.class) {
            Double d = c.getDouble(i);
            return (T) d;
        } else if (clazz == String.class) {
            String str = c.getString(i);
            return (T) str;
        } else if (clazz == Boolean.class) {
            // stored as integers
            Integer l = c.getInt(i);
            return (T) Boolean.valueOf(l != 0);
        } else if (clazz == ArrayList.class) {
            // json deserialization of an array
            String str = c.getString(i);
            return (T) ODKFileUtils.mapper.readValue(str, ArrayList.class);
        } else if (clazz == HashMap.class) {
            // json deserialization of an object
            String str = c.getString(i);
            return (T) ODKFileUtils.mapper.readValue(str, HashMap.class);
        } else {
            throw new IllegalStateException("Unexpected data type in SQLite table");
        }
    } catch (ClassCastException e) {
        e.printStackTrace();
        throw new IllegalStateException(
                "Unexpected data type conversion failure " + e.toString() + " in SQLite table ");
    } catch (JsonParseException e) {
        e.printStackTrace();
        throw new IllegalStateException(
                "Unexpected data type conversion failure " + e.toString() + " on SQLite table");
    } catch (JsonMappingException e) {
        e.printStackTrace();
        throw new IllegalStateException(
                "Unexpected data type conversion failure " + e.toString() + " on SQLite table");
    } catch (IOException e) {
        e.printStackTrace();
        throw new IllegalStateException(
                "Unexpected data type conversion failure " + e.toString() + " on SQLite table");
    }
}

From source file:org.apache.jmeter.protocol.http.parser.TestHTMLParser.java

private static void filetest(HTMLParser p, String file, String url, String resultFile, Collection<URLString> c,
        boolean orderMatters, // Does the order matter?
        String userAgent) throws Exception {
    String parserName = p.getClass().getName().substring("org.apache.jmeter.protocol.http.parser.".length());
    String fname = file.substring(file.indexOf('/') + 1);
    log.debug("file   " + file);
    File f = findTestFile(file);//  w ww  .  j  a v  a 2s  .c o  m
    byte[] buffer = new byte[(int) f.length()];
    InputStream is = null;
    try {
        is = new FileInputStream(f);
        int len = is.read(buffer);
        assertEquals(len, buffer.length);
    } finally {
        IOUtils.closeQuietly(is);
    }
    Iterator<URL> result;
    if (c == null) {
        result = p.getEmbeddedResourceURLs(userAgent, buffer, new URL(url),
                System.getProperty("file.encoding"));
    } else {
        result = p.getEmbeddedResourceURLs(userAgent, buffer, new URL(url), c,
                System.getProperty("file.encoding"));
    }
    /*
     * TODO: Exact ordering is only required for some tests; change the
     * comparison to do a set compare where necessary.
     */
    Iterator<String> expected;
    if (orderMatters) {
        expected = getFile(resultFile).iterator();
    } else {
        // Convert both to Sets
        expected = new TreeSet<>(getFile(resultFile)).iterator();
        TreeSet<URL> temp = new TreeSet<>(new Comparator<Object>() {
            @Override
            public int compare(Object o1, Object o2) {
                return (o1.toString().compareTo(o2.toString()));
            }
        });
        while (result.hasNext()) {
            temp.add(result.next());
        }
        result = temp.iterator();
    }

    while (expected.hasNext()) {
        Object next = expected.next();
        assertTrue(userAgent + "::" + fname + "::" + parserName + "::Expecting another result " + next,
                result.hasNext());
        try {
            assertEquals(userAgent + "::" + fname + "::" + parserName + "(next)", next,
                    result.next().toString());
        } catch (ClassCastException e) {
            fail(userAgent + "::" + fname + "::" + parserName + "::Expected URL, but got " + e.toString());
        }
    }
    assertFalse(userAgent + "::" + fname + "::" + parserName + "::Should have reached the end of the results",
            result.hasNext());
}

From source file:com.dimasdanz.kendalipintu.usermodel.UserDialogManager.java

public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {/*from ww  w .  j a  v a  2 s  .c  o m*/
        mListener = (UserDialogManagerListener) activity;
    } catch (ClassCastException e) {
        e.toString();
    }
}

From source file:me.lehrner.newsgroupsndy.view.AddServerActivity.java

@Override
public void onAttachFragment(Fragment fragment) {
    try {/*from  w  w  w .  ja v  a 2s .  co  m*/
        mServerClickHandlerWeakReference = new WeakReference<>((AddServerClickHandler) fragment);
    } catch (ClassCastException e) {
        Log.e(LOG_TAG, "Fragment doesn't implement AddServerClickHandler: " + e.toString());
    }
}

From source file:org.nuxeo.runtime.test.runner.web.WebDriverFeature.java

@Override
public void initialize(FeaturesRunner runner) throws Exception {
    browser = runner.getConfig(Browser.class);
    homepage = runner.getConfig(HomePage.class);
    DriverFactory factory;//from  ww w  .j av a 2s.  c  o  m
    // test here if the driver factory is specified by environment
    String fcName = System.getProperty(DriverFactory.class.getName());
    if (fcName != null) {
        factory = (DriverFactory) Class.forName(fcName).newInstance();
    } else {
        if (browser.factory() != DriverFactory.class) {
            factory = browser.factory().newInstance();
        } else {
            factory = browser.type().getDriverFactory();
        }
    }
    config = new Configuration(factory);
    config.setHomePageClass(homepage.type());
    // get the home page and the url - first check for an url from the
    // environment
    String url = System.getProperty(HomePage.class.getName() + ".url");
    if (url == null) {
        url = homepage.url();
    }
    config.setHome(url);
    try {
        runner.filter(new Filter() {
            @Override
            public boolean shouldRun(Description description) {
                SkipBrowser skip = description.getAnnotation(SkipBrowser.class);
                if (skip == null) {
                    return true;
                }
                for (BrowserFamily family : skip.value()) {
                    if (config.getBrowserFamily().equals(family)) {
                        return false;
                    }
                }
                return true;
            }

            @Override
            public String describe() {
                return "Filtering tests according to current browser settings";
            }
        });
    } catch (ClassCastException e) {
        // OK - just skip
    } catch (NoTestsRemainException e) {
        log.error(e.toString(), e);
    }
}

From source file:me.lehrner.newsgroupsndy.view.AddServerDialogFragment.java

@Override
public void onAttach(Context context) {
    super.onAttach(context);

    try {/*from www  .  ja  va 2  s.  com*/
        mGetServerId = (GetServerId) context;
    } catch (ClassCastException e) {
        Log.e(LOG_TAG, "Context doesn't implement GetServerId: " + e.toString());
    }
}