classcastexception

ClassCastException while using varargs and generics

我与影子孤独终老i 提交于 2019-12-01 19:20:33
I'm using java generics and varargs. If I use the following code, I'll get a ClassCastException , even though I'm not using casts at all. Stranger yet, if I run this on Android (dalvik) no stack trace is included with the exception, and if I change the interface to abstract class, the exception variable e is empty. The code: public class GenericsTest { public class Task<T> { public void doStuff(T param, Callback<T> callback) { // This gets called, param is String "importantStuff" // Working workaround: //T[] arr = (T[]) Array.newInstance(param.getClass(), 1); //arr[0] = param; //callback

How to get Boolean value from Object

久未见 提交于 2019-12-01 17:14:30
I tried different ways to fix this, but I am not able to fix it. I am trying to get the Boolean value of an Object passed inside this method of a checkBox: public boolean onPreferenceChange(Preference preference, Object newValue) { final String key = preference.getKey(); referenceKey=key; Boolean changedValue=!(((Boolean)newValue).booleanValue()); //ClassCastException occurs here } I get: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean Instead of casting it, you can do something like Boolean.parseBoolean(string); Here's some of the source code for the Boolean

Cannot cast eclipse project to IJavaProject

丶灬走出姿态 提交于 2019-12-01 16:29:42
I have the following code IJavaProject targetProject = null; IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (IProject project : root.getProjects()) { if (project.getName().equals(projName)) { try { if (project.hasNature("org.eclipse.jdt.core.javanature")) { targetProject = (IJavaProject) project; } } catch( ... ) { // etc ... } What I am trying to do is essentially return a project that matches a particular name as an IJavaProject. As you can see, I check to ensure that the project in question has a java nature by calling: if (project.hasNature("org.eclipse.jdt.core

How to get Boolean value from Object

允我心安 提交于 2019-12-01 16:27:12
问题 I tried different ways to fix this, but I am not able to fix it. I am trying to get the Boolean value of an Object passed inside this method of a checkBox: public boolean onPreferenceChange(Preference preference, Object newValue) { final String key = preference.getKey(); referenceKey=key; Boolean changedValue=!(((Boolean)newValue).booleanValue()); //ClassCastException occurs here } I get: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean 回答1: Instead of

Cannot cast eclipse project to IJavaProject

ⅰ亾dé卋堺 提交于 2019-12-01 15:59:16
问题 I have the following code IJavaProject targetProject = null; IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (IProject project : root.getProjects()) { if (project.getName().equals(projName)) { try { if (project.hasNature("org.eclipse.jdt.core.javanature")) { targetProject = (IJavaProject) project; } } catch( ... ) { // etc ... } What I am trying to do is essentially return a project that matches a particular name as an IJavaProject. As you can see, I check to ensure that

ClassCastException in between equal classes Wildfly 10

大兔子大兔子 提交于 2019-12-01 11:30:40
I am Creating a RESTful application and I am having trouble making a conversion for a new connection. My application server is Wildfly 10.0. DataSource and Driver in standalone-full.xml: <datasource jndi-name="java:jboss/datasources/PostgreDS" pool-name="PostgreDS" enabled="true" use-java-context="true"> <connection-url>jdbc:postgresql://192.168.0.112:5432/bdns</connection-url> <driver>postgresql</driver> <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation> <pool> <min-pool-size>10</min-pool-size> <max-pool-size>40</max-pool-size> <prefill>true</prefill> </pool> <security>

Catching ClassCastException in a generic method when doing generic cast

孤者浪人 提交于 2019-12-01 10:41:34
Suppose I have a method @SuppressWarnings("unchecked") public <T extends Number> T getNumber() { try { return (T)number; } catch (ClassCastException e) { return null; } } Assuming number is an instance of Integer , invoking method like Float f = getNumber(); results into a ClassCastException . I know (somehow) that this is because of type erasure but could someone provide more profound explanation why the exception escalates up to the assignment level and is not catchable inside method? NOTE: I do have the version public <T extends Number> T getNumber(Class<T> classT) that checks the type from

Catching ClassCastException in a generic method when doing generic cast

浪尽此生 提交于 2019-12-01 09:19:47
问题 Suppose I have a method @SuppressWarnings("unchecked") public <T extends Number> T getNumber() { try { return (T)number; } catch (ClassCastException e) { return null; } } Assuming number is an instance of Integer , invoking method like Float f = getNumber(); results into a ClassCastException . I know (somehow) that this is because of type erasure but could someone provide more profound explanation why the exception escalates up to the assignment level and is not catchable inside method? NOTE:

Unable to cast a class error

时间秒杀一切 提交于 2019-12-01 09:01:49
I am going to use rootbeer1 for the first time. I am in windows 7 machine, 32 bit system having GForce 610 GPU. I installed CUDA 5.5 successfully and executed the examples to make sure it works fine too. Then I installed rootbeer1 according to the guidance given in the github page. Then I loaded Rootbeer.jar into NetBeans IDE as an external jar and copied and pasted the example code of rootbeer which is listed in here . One change I made is changing the imports, where the code in github page imports import edu.syr.pcpratts.rootbeer.runtime.Rootbeer; import edu.syr.pcpratts.rootbeer.runtime

ClassCastException in between equal classes Wildfly 10

孤街醉人 提交于 2019-12-01 07:58:00
问题 I am Creating a RESTful application and I am having trouble making a conversion for a new connection. My application server is Wildfly 10.0. DataSource and Driver in standalone-full.xml: <datasource jndi-name="java:jboss/datasources/PostgreDS" pool-name="PostgreDS" enabled="true" use-java-context="true"> <connection-url>jdbc:postgresql://192.168.0.112:5432/bdns</connection-url> <driver>postgresql</driver> <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation> <pool> <min