classcastexception

Why doesn't TreeSet.contains() work?

public class Empty { public static void main( String[] args ) { TreeSet<Class> classes = new TreeSet<Class>(); classes.add( String.class ); String test = new String(); try{ if( classes.contains(test.getClass()) ){ System.out.println( "contains" ); } ...

Jboss ClassCastException issue

We have a project that we shoud update from ejb2.1 to 3.1 and jboss from 3.2.1 to latest Jboss6 milestone. Our Project Structure: we have an ear that contains application.xml, that points to ejb-jar(2.1) classes, but actual clasess are stored in WEB-INF/classes. Now when we load ejb via jndi we get it, but when we are trying to cast in ...

Try to make a process that can TSKILL itself

So I have a problem with a process that I am running, whenever I try to stop it using process.destroy(), it does not stop. I want to create a file (ProcessHandler) that extends Process and do the following: ProcessHandler process = (ProcessHandler)Runtime.getRuntime().exec("cmd.exe /c \"java net/com/codeusa/Server 43594\""); So, my p...

Class Loading to an interface

Hi, I'm quite restricted in the platform I'm currently working on (JDK 1.3, BD-J). One JAR file I would like to use attempts to perform a self-integrity check on load and if it fails it goes into an inoperable state. It's quite difficult to find out why this is happening but most sources point to that it cannot find/access it self throu...

ClassCastException in casting DTMManagerDefault into DTMManager during maven jaxb codegen

I'm having a strange problem when trying to run a maven build that uses the jaxb2 plugin to do JAXB codegen (see stacktrace below). The best that I can figure is that there's some implementation of DTMManager that's being class loaded from a different JAR than the one in xalan-2.7.1; however, I have verified that the classpath that is us...

android classcastexception on activity startup

hello, i have a simple activity program in android. basically the class just extends Activity. But when i start it i get a ClassCastException in the constructor of my class. i dont even have a constructor defined, so it must be in the constructor of the superclass which is Activity. unfortunately the debugger doesnt give any detailed in...

ClassCastException in Java foreach loop

In what circumstances can ClassCastException occur in the code below: import java.util.Arrays; import java.util.List; public class Generics { static List getObjects() { return Arrays.asList(1, 2, 3); } public static void main(String[] args) { List<String> list = getObjects(); for (Object o : list) ...

Hibernate -> ArrayList cannot be cast to Set

Hello! I have a Java EE application and I use Hibernate. The domain objects, I changed the List / ArrayList to Set / HashSet, because it is better to use Sets. But in my Dao implementation I run into a problem: public Set<Person> getAllPersons() { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session sess ...

Java: Unchecked cast from X to Y / how to implement castOrNull

Hi, I have implemented this function: static <X,Y> Y castOrNull(X obj) { try { return (Y)obj; } catch(ClassCastException e) { return null; } } This gives me the compiler warning: Type safety: Unchecked cast from X to Y Which I don't exactly understand. Isn't the try/catch which I am doing here a check for it? Can I...

"Iterable<Element> cannot be cast to List<Element>" - Isn't `List` a type of `Iterable`?

I called a getElements method which returns Iterable<Element>. I did this: List<Element> elements = (List<Element>) getElements(); This generates the error: java.lang.ClassCastException: com.utesy.Element$3 cannot be cast to java.util.List I thought a List was a type of Iterable? ...