Example usage for java.lang ClassCastException printStackTrace

List of usage examples for java.lang ClassCastException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:sysnetlab.android.sdc.ui.fragments.ExperimentSensorSelectionFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    try {/*ww  w  . java  2  s.co  m*/
        mCallback = (OnFragmentClickListener) activity;
    } catch (ClassCastException e) {
        Log.e("SensorDataCollector",
                "ExperimentSensorSelectionFragment::onAttach(): failed to cast Activity to OnFragmentClickListener.");
        e.printStackTrace();
        throw new RuntimeException("Failed to cast Activity to OnFragmentClickListener");
    }
}

From source file:org.opendatakit.common.android.data.Row.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  ww  w  .j av a  2  s  .  com*/
 * <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 elementKey
 * @param clazz
 * @return
 */
@SuppressWarnings("unchecked")
public final <T> T getRawDataType(String elementKey, Class<T> clazz) {
    // If you add additional return types here be sure to modify the javadoc.
    try {
        String value = getRawDataOrMetadataByElementKey(elementKey);
        if (value == null) {
            return null;
        }
        if (clazz == Long.class) {
            Long l = Long.parseLong(value);
            return (T) (Long) l;
        } else if (clazz == Integer.class) {
            Integer l = Integer.parseInt(value);
            return (T) (Integer) l;
        } else if (clazz == Double.class) {
            Double d = Double.parseDouble(value);
            return (T) (Double) d;
        } else if (clazz == String.class) {
            return (T) (String) value;
        } else if (clazz == Boolean.class) {
            // booleans are stored as integer 1 or 0 in user tables.
            return (T) (Boolean) Boolean.valueOf(!value.equals("0"));
        } else if (clazz == ArrayList.class) {
            // json deserialization of an array
            return (T) ODKFileUtils.mapper.readValue(value, ArrayList.class);
        } else if (clazz == HashMap.class) {
            // json deserialization of an object
            return (T) ODKFileUtils.mapper.readValue(value, HashMap.class);
        } else if (clazz == TreeMap.class) {
            // json deserialization of an object
            return (T) ODKFileUtils.mapper.readValue(value, TreeMap.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:com.z299studio.pb.DetailFragment.java

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    try {/*  w w w .ja v  a 2s .co  m*/
        mListener = (ItemFragmentListener) context;
    } catch (ClassCastException e) {
        e.printStackTrace();
    }
}

From source file:org.spout.api.lang.CommonPluginDictionary.java

@SuppressWarnings("unchecked")
protected void load() {
    Yaml yaml = new Yaml();

    // Load keymap
    InputStream in = openLangResource("keymap.yml");
    if (in == null) {
        return;//from   ww w.j  av a2  s.c  o  m
    }
    try {
        Map<String, Object> dump = (Map<String, Object>) yaml.load(in);
        if (dump.containsKey("nextId")) {
            nextId = (Integer) dump.get("nextId");
        }
        if (dump.containsKey("ids")) {
            Map<Integer, Map<String, String>> idmap = (Map<Integer, Map<String, String>>) dump.get("ids");
            for (Entry<Integer, Map<String, String>> e1 : idmap.entrySet()) {
                Integer id = e1.getKey();
                Map<String, String> contents = e1.getValue();
                String clazz, source;
                clazz = contents.get("class");
                source = contents.get("string");
                if (id != null && clazz != null && source != null) {
                    setKey(source, clazz, id);
                }
            }
        }
    } catch (ClassCastException e) {
        e.printStackTrace();
    }

    loadLanguages();
}

From source file:org.jgap.distr.Culture.java

/**
 * The equals-method./*from   www  . j a v  a 2 s.c o  m*/
 * @param a_other the other object to compare
 * @return true if the objects are regarded as equal
 *
 * @author Klaus Meffert
 * @since 3.0
 */
public boolean equals(Object a_other) {
    try {
        return compareTo(a_other) == 0;
    } catch (ClassCastException cex) {
        cex.printStackTrace();
        return false;
    }
}

From source file:com.ninetwozero.battlelog.ForumActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    // Declare...
    AdapterView.AdapterContextMenuInfo info;

    // Let's try to get some menu information via a try/catch
    try {//from  ww  w .j a  v  a 2  s  .c  om

        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    } catch (ClassCastException e) {

        e.printStackTrace();
        return false;

    }

    switch (viewPager.getCurrentItem()) {

    case 2:
        return fragmentForumThread.handleSelectedContextItem(info, item);

    default:
        break;

    }

    return true;

}

From source file:pl.schibsted.flume.interceptor.json.JsonInterceptor.java

@Override
public Event intercept(Event event) {
    try {/*from  w  ww  .j a v a  2 s. co  m*/

        String body = new String(event.getBody(), Charsets.UTF_8);
        Map<String, String> headers = event.getHeaders();
        //String value = JsonPath.read(body, headerJSONPath);
        JsonPath namePath = JsonPath.compile(headerJSONPath);
        String value = namePath.read(body, String.class);
        headers.put(headerName, serializer.serialize(value));

    } catch (java.lang.ClassCastException e) {
        logger.warn("Skipping event due to: ClassCastException.", e);
    } catch (Exception e) {
        logger.warn("Skipping event due to: unknown error.", e);
        e.printStackTrace();
    }
    return event;
}

From source file:com.rackspacecloud.blueflood.io.SerializationTest.java

@Test
public void testFullResRoundTrip() throws IOException {
    // tests serialization of all types that should be handled, including granularity variations.
    Object[] inputs = { 7565, 323234234235223321L, 213432.53323d, 42332.0234375f, toSerializeRollup[0],
            toSerializeRollup[1], toSerializeRollup[2], toSerializeRollup[3] };

    Object[] expected = { 7565, 323234234235223321L, 213432.53323d, 42332.0234375d, // notice that serialization converts to a double.
            toSerializeRollup[0], toSerializeRollup[1], toSerializeRollup[2], toSerializeRollup[3] };

    for (Granularity gran : Granularity.granularities()) {
        for (int i = 0; i < inputs.length; i++) {
            try {
                Object dst = NumericSerializer.get(gran)
                        .fromByteBuffer(NumericSerializer.get(gran).toByteBuffer(inputs[i]));
                Assert.assertEquals(String.format("busted at %s %d", gran.name(), i), expected[i], dst);
            } catch (ClassCastException ex) {
                ex.printStackTrace();
                Assert.fail("Serialization should address class type mismatches as IOExceptions");
            } catch (RuntimeException ex) {
                Assert.assertTrue(ex.getCause() instanceof SerializationException);
                if (gran == Granularity.FULL)
                    Assert.assertTrue(inputs[i] instanceof Rollup);
                else
                    Assert.assertFalse(inputs[i] instanceof Rollup);
            } catch (Throwable unexpected) {
                unexpected.printStackTrace();
                Assert.fail(String.format("Unexpected error at %s %d", gran.name(), i));
            }//from   w  w  w  .j  av a 2s . com
        }
    }
}

From source file:com.ninetwozero.battlelog.ProfileActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    // Declare...
    AdapterView.AdapterContextMenuInfo info;

    // Let's try to get some menu information via a try/catch
    try {//from w  w  w. j  a v a2 s .co m

        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    } catch (ClassCastException e) {

        e.printStackTrace();
        return false;

    }

    switch (viewPager.getCurrentItem()) {

    case 2:
        return fragmentFeed.handleSelectedContextItem(info, item);

    default:
        break;

    }

    return true;
}

From source file:com.ninetwozero.battlelog.PlatoonActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    // Declare...
    AdapterView.AdapterContextMenuInfo info;

    // Let's try to get some menu information via a try/catch
    try {//w w w.j  a  va2s .  c om

        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    } catch (ClassCastException e) {

        e.printStackTrace();
        return false;

    }

    switch (viewPager.getCurrentItem()) {

    case 2:
        return fragmentMember.handleSelectedContextItem(info, item);

    case 3:
        return fragmentFeed.handleSelectedContextItem(info, item);

    default:
        break;

    }

    return true;
}